Azure devops 基于提交消息跳过阶段
我正在尝试将Azure DevOps设置为,如果消息不是以给定文本开头,则跳过上的某个阶段 从表面上看,我认为这只是Azure devops 基于提交消息跳过阶段,azure-devops,azure-pipelines,multistage-pipeline,Azure Devops,Azure Pipelines,Multistage Pipeline,我正在尝试将Azure DevOps设置为,如果消息不是以给定文本开头,则跳过上的某个阶段 从表面上看,我认为这只是 - stage: t1 condition: not(startsWith(variables['Build.SourceVersionMessage'], '[maven-release-plugin]')) jobs: - job: ReleasePrepare displayName: Prepare release
- stage: t1
condition: not(startsWith(variables['Build.SourceVersionMessage'], '[maven-release-plugin]'))
jobs:
- job: ReleasePrepare
displayName: Prepare release
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
env | sort
然而,不管怎样,这都会得到执行。下面是一个示例,我希望不会基于提交消息运行t1
任务
env
的输出显示消息已正确传入
以防万一这是一个错误,我在这里也报告了它
我正在尝试将Azure DevOps设置为在消息未发送时跳过某个阶段
从给定的文本开始
如果我没有误解,您需要的条件是,如果消息与开头与maven release plugin
匹配,则当前阶段将排队
如果您写的条件不正确,我认为您应该指定它:
startsWith(variables['Build.SourceVersionMessage'], '[maven-release-plugin]')
当我在管道上测试时:
事实上,这个变量的值是Deleted 121321。结果如下:
正如你所看到的,跳过这个阶段是成功的。我的逻辑是,Build.SourceVersionMessage
的值应该以othermessage
开头。但事实上,在我的管道中,它的值是Deleted 121321
。不匹配,因此跳过此阶段
(Delete 121321不仅仅是我的PR名称,我只是将提交消息设置为默认PR名称。)
更新2:
虽然我的测试逻辑没有错误,但在我使用YAML和许多其他测试方法复制之后,例如使用Build.SourceVersion,它只能在源代码拉取之后才能获得
是的,关于构建,您是对的。SourceVersionMessage在工作级别没有价值。根据我的测试,它在工作级别上确实null
但是,不幸的是,这不是一个bug。事实上,这是我们设计的
我们可以认为,只有阶段作业开始执行时,源回购才会在本地被拉入,对吗?您可以看到签出日志,它记录了有关下拉源文件的过程
如果不执行该阶段,则不会下拉源。但是,如果没有拉取源,服务器也将无法获取Build.SourceVersionMessage的值,因为没有源历史记录。这就是为什么我还在作业级别中使用变量Build.SourceVersion进行测试
我们无法在代理作业级别使用这两个变量,因为它尚未提取源,因此Build.SourceVersionMessage为null。您需要将其复制到管道中的每个步骤。这是我们产品组团队确认的内容
但是,我仍然需要说对不起。很抱歉,我们的文档不太清楚,无法宣布这无法用于代理作业级别。在撰写本文时,
Build.SourceVersionMessage
似乎只能在步骤中解决
下面是一个工作示例,它在一个步骤中将值存储在变量中,并在下一个作业中使用它(可以是部署
)
构建可以在您误解的中找到。如果它不是以给定文本开头,我希望它跳过。其次,我希望它来自提交消息而不是PR标题为了证明它不仅是我的PR名称,我使用powershell打印变量值。查看我的更新内容。另外,如果不是以给定的文本开始,跳过不是意味着如果是以给定的文本开始,它不会被跳过,阶段将被执行吗?在shell中它是存在的。但是,如果你能提供一个示例公共管道,至少我可以与我的进行比较。我在我的env | sort
输出中看到BUILD\u SOURCEVERSIONMESSAGE
,所以至少我知道它存在,但它不在舞台级别上。它在“作业”级别上也是空的,而不仅仅是在“舞台”级别上。因此,只需指出它仅处于代码的“步骤”级别。Thx。工作起来很有魅力!文档似乎已经更新,现在它明确表示,它仅在步骤级别可用
trigger:
batch: true
branches:
include:
- master
stages:
- stage: ci
displayName: Continuous Integration
jobs:
- job: Build
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
env | sort
echo "$(Build.SourceVersionMessage)"
- stage: t1
displayName: Release
condition: eq(variables['Build.SourceBranch'],'refs/heads/master')
jobs:
- job: GetCommitMessage
displayName: Get commit message
steps:
- bash: |
echo "##vso[task.setvariable variable=commitMessage;isOutput=true]$(Build.SourceVersionMessage)"
echo "Message is '$(Build.SourceVersionMessage)''"
name: SetVarStep
displayName: Store commit message in variable
- job: ReleasePrepare
displayName: Prepare release
dependsOn: GetCommitMessage
pool:
vmImage: 'ubuntu-16.04'
condition: not(startsWith(dependencies.GetCommitMessage.outputs['SetVarStep.commitMessage'], '[maven-release-plugin]'))
steps:
- script: |
echo this would be a candidate for release
env | sort
displayName: Don't do it if maven release
- job: NotReleasePrepare
displayName: Don't Prepare Release
dependsOn: GetCommitMessage
pool:
vmImage: 'ubuntu-16.04'
condition: startsWith(dependencies.GetCommitMessage.outputs['SetVarStep.commitMessage'], '[maven-release-plugin]')
steps:
- script: |
echo this not be a candidate for release because it was created by the plugin
env | sort
condition: startsWith(variables.commitMessage, '[maven-release-plugin]')
displayName: Do it if maven release