简体   繁体   English

如何区分 azure DevOps 构建管道中的分支触发器和计划触发器

[英]How to differentiate between branch trigger and the scheduled trigger in azure DevOps build pipeline

I want to run different jobs in build pipeline for branch trigger and scheduled trigger.我想在构建管道中为分支触发器和计划触发器运行不同的作业。

branch trigger => run job 1

scheduled trigger => run job 2

Is there any way to differentiate between the triggers ?有什么方法可以区分触发器吗? So that i will be running my jobs according to that differentiating condition.这样我就可以根据这种差异化条件来运行我的工作。

My thought process我的思考过程

I was thinking of setting variable during scheduled trigger, hence i could use that variable in the job condition evaluation.我正在考虑在预定触发期间设置变量,因此我可以在作业条件评估中使用该变量。 But I was not able set the variable.但我无法设置变量。

# 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


You can differentiate the type of Trigger using the variable named Reason您可以使用名为 Reason 的变量来区分触发器的类型

condition: and(succeeded(), and(not(eq(variables['Build.Reason'], 'PullRequest')), not(eq(variables['Build.Reason'], 'Schedule'))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM