how to get warning badge in azure devops pipeline at tasks level? - Stack Overflow

admin2025-04-17  3

badge is shown in this pic in orange color:

I have tried below pipeline. but not getting warning badge.

trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: |
    echo "Parsing JSON output..."
    echo "##[error]Warning: some message"
  displayName: "Force Warning as Error"

badge is shown in this pic in orange color:

I have tried below pipeline. but not getting warning badge.

trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: |
    echo "Parsing JSON output..."
    echo "##[error]Warning: some message"
  displayName: "Force Warning as Error"
Share Improve this question edited Jan 31 at 12:35 Rui Jarimba 18.2k11 gold badges64 silver badges98 bronze badges Recognized by CI/CD Collective asked Jan 30 at 19:51 Deepak BhartiDeepak Bharti 211 silver badge1 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 2

The echo "##[warning]Warning message" command is used to mark the log as warning, affect the display as below but not the task result with badge.

To get warning badge:

One option is to use command echo "##vso[task.complete result=SucceededWithIssues;]" as mentioned by @ScottRichards. The limitation is you need to make sure the task is NOT failed. If it's failed, it will still get failed badge.

In this scenario, we can consider another option, we can setcontinueOnError option as true. sample as below:

- script: |
    exit 1              ### the command fails but task is succeededwithissue with continuesOnError
  continueOnError: true
  displayName: 'Force Warning'

Task with warning badge:

You can also consider to combine two options together, so that no matter the command result is failed or not, the task will get warning badge.

- script: |
    any command
    echo "##vso[task.complete result=SucceededWithIssues;]"
  continueOnError: true
  displayName: 'Force Warning'

You can run this command in a script to force the result of a pipeline task:

- script: echo "##vso[task.complete result=SucceededWithIssues;]"

Possible task results are:

  • Succeeded
  • SucceededWithIssues
  • Failed

See more here: https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#example-1

转载请注明原文地址:http://anycun.com/QandA/1744893898a89124.html