我正在尝试提取触发管道的 webhook,因为 azure 在运行时参数中以 JSON 格式发送了此信息。我想找回名字。
我尝试将参数转换如下:
echo ${{ convertToJson(parameters) }} | sed -E 's/^([^:]+) :.*/\1/ ```
to resume I have 2 webhooks in my pipeline and I want to retrieve the webhook that triggered the pipeline to choose which job will execute
I tried this simple test **yet it keep skipping without any output:
resources:
webhooks:
- webhook: webhook1
connection: ServiceConnection1
- webhook: webhook2
connection: ServiceConnection2
trigger:
branches:
include:
- main
stages:
- stage: Stage1
condition: eq(variables['resources.webhooks[2].webhook'], 'webhook1')
jobs:
- job: Job1
steps:
- script: echo "This stage is triggered by webhook1"
- stage: Stage2
condition: eq(variables['resources.webhooks[2].webhook'], 'webhook2')
jobs:
- job: Job1
steps:
- script: echo "This stage is triggered by webhook2" ```
如何从 azure devops 中提取运行时参数名称?我想提取触发管道的 Webhook 名称?
为了满足您的要求,您可以使用管道变量:RESOURCES.TRIGGERINGALIAS。它将显示触发管道的 Webhook 名称。
这是一个例子:
resources:
webhooks:
- webhook: webhook1
connection: ServiceConnection1
- webhook: webhook2
connection: ServiceConnection2
stages:
- stage: Stage1
condition: eq(variables['RESOURCES.TRIGGERINGALIAS'], 'webhook1')
jobs:
- job: Job1
steps:
- script: echo "This stage is triggered by webhook1"
- stage: Stage2
condition: eq(variables['RESOURCES.TRIGGERINGALIAS'], 'webhook2')
jobs:
- job: Job1
steps:
- script: echo "This stage is triggered by webhook2"
当管道被其中一个 Webhook 触发时,它将运行目标阶段。
结果: