0

I keep getting the following problem in my pipeline when passing a runtime variable into the following two CLI commands.

az webapp create --resource-group $(RG) --plan $(azureSubscription) --name "%APPNAME%"'

az webapp config appsettings set --name "%APPNAME%"' --resource-group $(RG) --settings '/home/vsts/work/1/s/studentsettings.json' --subscription $(azureSubscription)

This is the Error:

/home/vsts/work/_temp/azureclitaskscript1617264397722.sh: line 1: syntax error near unexpected token `('

I have attached a snippet of the code that I have made please can someone help me. I have spent 8 hours trying to fix this and a late night. I need this to work...

- job: job2
  displayName: 'Get Variable Value for Student Env'
  dependsOn: job1
  steps:
  - task: AzureCLI@1
    displayName: 'Azure CLI '
    inputs:
      azureSubscription: $(azureSubscription)
      scriptLocation: inlineScript
      inlineScript: |
        mkdir $(Pipeline.Workspace)\BlobFile
        az storage blob download --container-name $(containername) --file '$(Pipeline.Workspace)/s/student.json' --name 'student.json' --connection-string 'MY VALUE'
        az storage blob download --container-name 'private' --file '$(Pipeline.Workspace)/s/studentsettings.json' --name 'studentappsettings.json' --connection-string 'MY VALUE'
  - pwsh: |
      cd '/home/vsts/work/1/s/'
      ls
      $armOutput = Get-Content '/home/vsts/work/1/s/student.json' | convertfrom-json
      $student = $armOutput.studentvalue #use student not studentvalue
      $type = $armOutput.type
      $appservice = $armOutput.appservicevalue
      Write-Host "The value of [$student] is [$appservice]"
      Write-Host "##vso[task.setvariable variable=studentvalue;isOutput=true]$student" #use studentvalue not $studentvalue
      Write-Host "##vso[task.setvariable variable=appservicevalue;isOutput=true]$appservice" #use appservicevalue not $appservice
    name: setvarStep

  - script: echo $(setvarStep.studentvalue)
  - script: echo $(setvarStep.appservicevalue)
    name: echovar
  
- job: job3
  displayName: Create Web App 
  dependsOn: job2
  variables:
    webappname: $[ dependencies.job2.outputs['setvarStep.studentvalue'] ]
    appservicename: $[ dependencies.job2.outputs['setvarStep.appservicevalue'] ]
  steps:
  - script: export APPNAME=webappname  
  - script: echo %APPNAME%
  - script: export APPPLAN=appservicename
  - script: echo %APPPLAN%

# Create Web App
  - task: AzureCLI@1
    displayName: 'Create Web App in $(appservicename)'
    inputs:
      azureSubscription: $(azureSubscription)
      scriptLocation: inlineScript
      inlineScript: |
        az webapp create --resource-group $(RG) --plan $(azureSubscription) --name "%APPNAME%"'

 # Download Artifact File
  - download: none
  - task: DownloadPipelineArtifact@2
    displayName: 'Download Build Artifacts'
    inputs:
      patterns: '**/*.zip'
      path: '$(Build.ArtifactStagingDirectory)'

  # deploy to Azure Web App 
  - task: AzureWebApp@1
    displayName: 'Azure Web App Deploy: $(webappname)'
    inputs:
      package: $(Build.ArtifactStagingDirectory)/**/*.zip 
      azureSubscription: $(appconnectionname)
      ConnectedServiceName: $(appconnectionname)
      appName: '$(webappname)'
      ResourceGroupName: $(RG)  

  # Change App Settings
  - task: AzureCLI@1
    displayName: 'Change WebApp Settings'
    inputs: 
     azureSubscription: $(azureSubscription)
     scriptLocation: inlineScript
     inlineScript: |
       az webapp config appsettings set --name "%APPNAME%"' --resource-group $(RG) --settings '/home/vsts/work/1/s/studentsettings.json' --subscription $(azureSubscription)
Jason
  • 510
  • 5
  • 27
  • The part that is broken is this bit: # Create Web App - task: AzureCLI@1 displayName: Create Web App in $(appservicename) inputs: azureSubscription: '$(azureSubscription)' scriptLocation: 'inlineScript' inlineScript: 'az webapp create -g $(RG) -p $(azureSubscription) -n $(webappname)' – Jason Apr 01 '21 at 10:41

1 Answers1

0

/home/vsts/work/_temp/azureclitaskscript1617264397722.sh: line 1: syntax error near unexpected token `('

From the error messages, it seems that there are some issue with the format of Azure Cli command.

There are two points you need to check:

1.In the Azure CLI command, It contains an extra character ' at the end of the command.

2.You could try to use the format $(webappname) to call the variable instead of %APPNAME%

Here is an example:

- job: job3
  displayName: Create Web App 
  dependsOn: job2
  variables:
    webappname: $[ dependencies.job2.outputs['setvarStep.studentvalue'] ]
    appservicename: $[ dependencies.job2.outputs['setvarStep.appservicevalue'] ]
  steps:
  - script: |
     set APPNAME=webappname  


  - script: echo %APPNAME%
  - script: export APPPLAN=appservicename
  - script: echo %APPPLAN%

# Create Web App
  - task: AzureCLI@1
    inputs:
      azureSubscription: $(azureSubscription)
      scriptLocation: 'inlineScript'
      inlineScript: |
        az webapp create --resource-group $(RG) --plan $(azureSubscription) --name $(webappname)
Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • I did try that but it didnt work. I even found a blog post with the correct syntax but when I use the command Az Web Create with runtime variables it gets a syntax error, when I put in actual values instead of variables it runs. – Jason Apr 06 '21 at 08:10
  • Hi @Jason. How do you define the variable $(RG) and $(azureSubscription)? – Kevin Lu-MSFT Apr 06 '21 at 08:18
  • at the top of the yaml file ive done a variables then defiened them both there why? – Jason Apr 06 '21 at 13:23
  • When you use the this format `$(variablename)`, are you still get the same error? Based on my test, it could work fine. On the other hand, you need check variable case because Linux system is case sensitive. – Kevin Lu-MSFT Apr 06 '21 at 13:26