【问题标题】:how to set condition for pull request and non-pullrequest stage in azure devop pipeline?如何在 azure devop 管道中设置拉取请求和非拉取请求阶段的条件?
【发布时间】:2021-03-26 21:00:57
【问题描述】:

我正在学习使用 azure devop 的 yaml 管道。

在一个阶段,我把这个条件放在

condition: and(succeeded(), eq(variables['System.PullRequest.PullRequestId'], 'Null')
variables:
  prId: $(System.PullRequest.PullRequestId)
  reason: $(Build.Reason)

基本上只在不是拉取请求时才运行此阶段。但是,当我手动触发管道时,azure devop 决定跳过此操作。所以我添加了构建原因和 pullrequestId 作为变量然后输出它。

write-host "------------------------------"
write-host '$(reason)'
write-host "------------------------------"
write-host '$(prId)' 

输出是:

Manual

$(System.PullRequest.PullRequestId)

我在想,当它不是由 PullRequest 触发时,$(System.PullRequest.PullRequestId) 应该为 null 或空字符串。看起来情况并非如此。文档说 PullRequestId 只有在拉取请求时才会被填充,但我真的不知道没有填充时的值是什么。至少看起来不是 Null。

那么除了 PullRequestId 之外,构建原因是 PR 或非 PR 运行之间不同的可靠条件吗?

【问题讨论】:

    标签: azure-devops azure-devops-yaml


    【解决方案1】:

    那么 buildreason 是 PR 或非 PR 运行而不是 PullRequestId 之间不同的可靠条件吗?

    是的。您可以使用以下脚本:

    condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
    

    文档说 PullRequestId 只有在拉取请求时才会被填充,但不填充时我真的不知道它的值是什么。

    未填充时变量不存在。所以在你的情况下,variables['System.PullRequest.PullRequestId'] 的值是'System.PullRequest.PullRequestId'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多