I’m creating a YAML release script for Azure DevOps.
I’m still testing how to differentiate between a manual trigger/other pipeline trigger and a trigger coming from a webhook and how to conditionally execute some other logic (f.e. different approvals, …).
Currently I have the following YAML:
trigger: none
resources:
pipelines:
- pipeline: buildPipeline
source: 'POC - Build'
trigger:
branches:
include:
- develop
webhooks:
- webhook: Trigger
connection: Connection
filters:
- path: ReleaseName
value: Plugins
variables:
- name: isAutomatedTrigger
value: $[
and(
eq(variables['Build.reason'], 'ResourceTrigger'),
eq(variables['resources.triggeringAlias'], 'KristaDeploymentTrigger')
)
]
stages:
- stage: Test
jobs:
- job:
steps:
- checkout: none
- ${{if eq(variables.isAutomatedTrigger, True)}}:
- script: echo 'This is an automated trigger'
- ${{else}}:
- script: echo 'This is not an automated trigger'
When I execute the script starting it manually in DevOps, DevOps shows me the ‘isAutomatedTrigger’ parameter evaluates to False.
When i start the script using the webhook, DevOps shows me the parameter evaluaties to true.
However in both situations the text ‘This is not an automated trigger’ is printed.
I tried different spellings of True, true, ‘True’, …
I tried not using the eq (just if(variables.isAutomatedTrigger), … but nothing helps.
I also tried the different variable notation: variables[‘isAutomatedTrigger’].
Sometimes the result switches: both the manual and webhook trigger of the pipeline result in ‘This is an automated trigger’ but never do they behave like intended, even if the parameter always evalaates correctly