skip to Main Content

How to determine success or failure in Azure Pipeline stage, based on logs?

I have following output and I’d like to set status as failed based on message from logs.

enter image description here

How to edit .yaml file to achieve this?
My .yaml step looks like:

- task: AzureCLI@2
        displayName: Deploy function ${{ parameters.package_name }}
        retryCountOnTaskFailure: 10
        inputs:
          workingDirectory: $(Pipeline.Workspace)/${{ parameters.package_name }}
          azureSubscription: ${{ variables.azure_subscription }}
          scriptType: bash
          scriptLocation: inlineScript
          inlineScript: >
            func azure functionapp publish func-tfm-${{ parameters.package_name }}-${{ variables.env_reg_long }} --python

2

Answers


  1. Ah it’s a script step, that makes things easier.

    You can capture the output from az into a variable, then check the output.

    $output= & az ... ... ...
    if ($output -like "*the errormessage*')
    {
      echo "##vso[task.complete result=Failed;]Failed"
    }
    

    If you still want to stream the content it’s a little more work.

    In many cases, instead of checking the contents, you can probably check the last exit code:

    & az ... ... ...
    if ($LASTEXITCODE -ne 0)
    {
        echo "##vso[task.complete result=Failed;]Failed
    }
    

    You may also be able to set the property on the script step to fail on output to Standard Error:

    - task: AzureCLI@2
      failOnStandardError: true
      powerShellErrorActionPreference: "stop"
    
    Login or Signup to reply.
  2. An example of capturing the error code from a bash command:

    if [ $? -ne 0 ]; then
        echo "##vso[task.complete result=Failed;]Failed"
    fi
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search