如何区分 azure DevOps 构建管道中的分支触发器和计划触发器
How to differentiate between branch trigger and the scheduled trigger in azure DevOps build pipeline
我想 运行 为分支触发器和计划触发器构建管道中的不同作业。
branch trigger => run job 1
scheduled trigger => run job 2
有什么方法可以区分触发器?这样我就会 运行 根据不同的条件来安排我的工作。
我的思考过程
我正在考虑在计划触发期间设置变量,因此我可以在工作条件评估中使用该变量。但是我无法设置变量。
# Sample azure-build-pipeline.yml file
variables:
# by default the variable is false
isScheduledTrigger: false
trigger:
- develop
- master
schedules:
- cron: "0 0 * * *"
displayName: Daily midnight build
branches:
include:
- develop
always: true
# somewhere here i want to set the isScheduledTrigger variable to TRUE
jobs:
- job: Branch trigger job
condition: or(eq(variables['Build.SourceBranchName'], 'develop'),eq(variables['Build.SourceBranchName'], 'master'))
steps:
# Multiple steps for branch trigger
- job: Scheduled trigger job
condition: and(eq(variables['Build.SourceBranchName'], 'develop'),eq(variables['isScheduledTask'], True))
steps:
# Multiple steps for scheduled trigger
您可以使用名为 Reason 的变量来区分触发器的类型
condition: and(succeeded(), and(not(eq(variables['Build.Reason'], 'PullRequest')), not(eq(variables['Build.Reason'], 'Schedule'))))
我想 运行 为分支触发器和计划触发器构建管道中的不同作业。
branch trigger => run job 1
scheduled trigger => run job 2
有什么方法可以区分触发器?这样我就会 运行 根据不同的条件来安排我的工作。
我的思考过程
我正在考虑在计划触发期间设置变量,因此我可以在工作条件评估中使用该变量。但是我无法设置变量。
# Sample azure-build-pipeline.yml file
variables:
# by default the variable is false
isScheduledTrigger: false
trigger:
- develop
- master
schedules:
- cron: "0 0 * * *"
displayName: Daily midnight build
branches:
include:
- develop
always: true
# somewhere here i want to set the isScheduledTrigger variable to TRUE
jobs:
- job: Branch trigger job
condition: or(eq(variables['Build.SourceBranchName'], 'develop'),eq(variables['Build.SourceBranchName'], 'master'))
steps:
# Multiple steps for branch trigger
- job: Scheduled trigger job
condition: and(eq(variables['Build.SourceBranchName'], 'develop'),eq(variables['isScheduledTask'], True))
steps:
# Multiple steps for scheduled trigger
您可以使用名为 Reason 的变量来区分触发器的类型
condition: and(succeeded(), and(not(eq(variables['Build.Reason'], 'PullRequest')), not(eq(variables['Build.Reason'], 'Schedule'))))