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

标签 azure azure-devops azure-pipelines azure-pipelines-build-task azure-pipelines-yaml

我想在构建管道中为分支触发器和计划触发器运行不同的作业。

分支触发器 => 运行作业 1

计划触发器 => 运行作业 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'))))

关于azure - 如何区分azure DevOps构建管道中的分支触发器和计划触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61308555/

相关文章:

azure - 在 Windows Phone 8 和 Windows 8 Store 应用程序之间共享数据

node.js - 在 Azure 的 IISNode 上调用本地主机 URL

azure - 当从功能分支创建 PR 到开发分支时,PR 触发器如何工作?构建是否在目标分支触发

azure-devops - Azure DevOps 更改代理池

azure - 单一作业阶段的最佳实践 - Azure Pipeline yaml

azure-pipelines - Azure Pipelines DownloadPipelineArtifact 未下载项目

从 VSTS build 构建解决方案时出现 MSBuild 错误

python - Azure 默认日志

git - 尝试对 Azure Devops 执行 git push 时登录失败

c# - 在 Azure Functions 中使用 Ninject 确定 Entity Framework 的范围