Home > database >  Azure Devops Pipeline task (Azure CLI@2) failing
Azure Devops Pipeline task (Azure CLI@2) failing

Time:01-24

I have the below step in the Azure pipeline

  - task: AzureCLI@2
    displayName: get Logic App SAS Token
    name: getLogicAppSASToken1
    inputs:
      azureSubscription: ${{ parameters.serviceAccount }}
      scriptType: pscore
      scriptLocation: inlineScript
      inlineScript: |              
        $workflowDetails1 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME1)/triggers/manual/listCallbackUrl?api-version=2018-11-01
        $workflowResponse1 = $workflowDetails1 | ConvertFrom-Json
        $nameValueBody1 = '{"Name":"Workflow1","value":"'   $workflowResponse1.queries.sig   '"}'
        echo $nameValueBody1
        $workflowDetails2 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME2)/triggers/manual/listCallbackUrl?api-version=2018-11-01
        $workflowResponse2 = $workflowDetails2 | ConvertFrom-Json
        $nameValueBody2 = '{"Name":"Workflow2","value":"'   $workflowResponse2.queries.sig   '"}'
        echo $nameValueBody2

Below is what I see in the logs

/usr/bin/az account set --subscription 4xxxxxxxxxxxxxxxxxxxxxxxx0313
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command . '/myagent/_work/_temp/azureclitaskscript1674363859719.ps1'
{"Name":"Workflow1","value":"oxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxA"}
ERROR: Bad Request({"Code":"BadRequest","Message":"Encountered an error (ServiceUnavailable) from host runtime.","Target":null,"Details":[{"Message":"Encountered an error (ServiceUnavailable) from host runtime."},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","Message":"Encountered an error (ServiceUnavailable) from host runtime."}}],"Innererror":null})
{"Name":"Workflow2","value":""}
##[error]Script failed with exit code: 1
/usr/bin/az account clear

If you see the logs, the first API call works fine and I get the SAS Token of the Logic App Workflow. However, the second call is failing with an error as seen in the logs below. The thing that stumps me is how come the first call works and the second fails. So I assume it's not because of any configuration as if that's the case, I believe all calls should fail.

Any pointers please? Thank you!

CodePudding user response:

Not sure of the exact reason why it worked. But introducing a delay of 10 seconds between the 2 API calls did the trick! Refer below.

  - task: AzureCLI@2
    displayName: get Logic App SAS Token
    name: getLASASToken1
    inputs:
      azureSubscription: ${{ parameters.serviceAccount }}
      scriptType: pscore
      scriptLocation: inlineScript
      inlineScript: |              
        $workflowDetails1 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME)/triggers/manual/listCallbackUrl?api-version=2018-11-01 --debug
        $workflowResponse1 = $workflowDetails1 | ConvertFrom-Json
        $nameValueBody1 = '{"Name":"Workflow1-SASToken","value":"'   $workflowResponse1.queries.sig   '"}'
        echo $nameValueBody1
  - task: PowerShell@2
    inputs:
      displayName: 'Delay'
      targetType: 'inline'
      script: |
        Start-Sleep -Seconds 10
      pwsh: true
  - task: AzureCLI@2
    displayName: get Logic App SAS Token 2
    name: getLASASToken2
    inputs:
      azureSubscription: ${{ parameters.serviceAccount }}
      scriptType: pscore
      scriptLocation: inlineScript
      inlineScript: |              
        $workflowDetails2 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME)/triggers/manual/listCallbackUrl?api-version=2018-11-01 --debug
        $workflowResponse2 = $workflowDetails2 | ConvertFrom-Json
        $nameValueBody2 = '{"Name":"Workflow2-SASToken","value":"'   $workflowResponse2.queries.sig   '"}'
        echo $nameValueBody2
  • Related