Search code examples
azuretfsazure-pipelinesazure-pipelines-yaml

Azure Devops Server Pipelines: Any way to have a Stage result as "Succeeded" even if a constituent Job reported "SucceededWithIssues"?


Some tasks are expected to fail. Fortunately we have "continueOnError" for that. However, that results in the job being marked as "succeededWithIssues" which would be fine except it then taints the stage with the orange exclamation mark, which in turn taints the whole pipeline with the orange exclamation mark.

Is there a way to say "this stage is fully succeeded even though one of its constituent jobs succeeded with issues"?


Solution

  • Any way to have a Stage result as "Succeeded" even if a constituent Job reported "SucceededWithIssues"?

    I'm afraid it's not supported to change the stage result, but it supports to change the whole build result as succeed with rest api. You can put the script in last stage to update the build result.

            - powershell: |
                # Define parameters
                $organization = "testorg"
                $project = "testproject"
    
                # Base64-encode the personal access token
                $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$(token)"))
    
                # Define the API URL
                $uri = "https://dev.azure.com/$organization/$project/_apis/build/builds/$(Build.BuildId)" + "?api-version=7.1"
    
                echo $uri
    
                # Define the body of the request
                $body = @{
                    status = "completed"
                    result = "succeeded"
                } | ConvertTo-Json
    
                # Make the API request
                $response = Invoke-RestMethod -Uri $uri -Method Patch -Body $body -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
    
                # Output the response
                $response
    

    The stageA is succeededwithIssue, the whole build is succeed.

    enter image description here

    If you have only one stage, it will show stage result with green mark.

    enter image description here