I'm trying to send a post-build Slack message after the job is done/failed in a Azure DevOps YAML pipeline. But it seems I can't find a proper condition setting.
Basically, I have three stages: test, build, and notification.
I tried the following at last, but dependencies.UnitTest.result
returns null
, so not giving me Succeeded or Failed.
I also tried a bunch of different conditions but they didn't work. For example, a plain succeeded()
and failed()
without dependencies, or succeeded('Test')
as stage level or succeeded('UnitTest')
as job level.
In most cases, they send the success message even if they failed at the Test stage, or a syntax error for job names as argument in succeeded()
or failed()
What is the proper condition to send a post-build message like Jenkins?
stages:
- stage: Test
jobs:
- job: UnitTest
steps:
- script: echo UnitTest
- script: exit 1
- stage: Build
jobs:
- job: Build
steps:
- script: echo Build
- stage: Notify
dependsOn:
- Test
- Build
condition: succeededOrFailed()
jobs:
- job: Succeed
condition: eq(dependencies.UnitTest.result, 'Succeeded')
steps:
- script: echo Succeed #(slack)
- job: Fail
condition: eq(dependencies.UnitTest.result, 'Failed')
steps:
- script: echo Fail #(slack)
--- EDIT ---
MS support confirmed jobs in multi stages can't support as yaml syntax itself.
Not same as the original flow as expected, but you can split succeed and fail into different stages as follow. (It may increase quite number of stages just for the notification if you want different message for each jobs..)
...
- stage: Notify_Succeeded
condition: succeeded()
jobs:
- job: Succeed
steps:
- script: echo Succeed #(slack)
- stage: Notify_Fail
condition: failed()
jobs:
- job: Fail
steps:
- script: echo Fail #(slack)