根据提交消息跳过阶段
Skipping stage based on commit message
我正在尝试将 Azure DevOps 设置为在消息未以给定文本开头时跳过 multi-stage pipeline 的阶段。
从examples documentation来看,我认为只是
- 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
任务不会 运行 基于提交消息 https://dev.azure.com/trajano/experiments/_build/results?buildId=110&view=results
env
的输出显示消息已正确传入
以防万一这是一个错误,我也在这里报告了它https://developercommunity.visualstudio.com/content/problem/697290/startswith-buildsourceversionmessage-variable-not.html
I am trying to set Azure DevOps to skip a stage if a message does not
start with a given text.
如果我没理解错的话,你要的条件是如果消息匹配开头为maven-release-plugin
,则当前阶段会排队。
如果这样,你写的条件不对,我觉得你应该指定一下:
startsWith(variables['Build.SourceVersionMessage'], '[maven-release-plugin]')
正如我在管道上测试的那样:
而实际上这个变量的值是删除121321。这是结果:
如您所见,跳过阶段成功。我的逻辑是,Build.SourceVersionMessage
的值应该以othermessage
开头。但实际上,在我的管道中,它的值是Deleted 121321
。不匹配,所以跳过这个阶段。
(删除121321不仅是我的PR名称,我只是将commit message设置为默认PR名称。)
更新2:
虽然我的测试逻辑没有错,但是经过我用YAML复现等很多方法测试过,比如用Build.SourceVersion只能追源码拉。
是的,你是对的 Build.SourceVersionMessage 在工作级别没有价值。经过我的测试,它确实 null 在工作级别。
但是,不幸的是,这不是错误。这是实际设计的。
我们可以认为只有stage job开始执行才把source repos拉到本地,对吧?可以看到Checkout日志,它记录了拉取源文件的过程。
如果stage不执行,则source不会拉下来。而且,如果没有源拉取,服务器也将无法获取 Build.SourceVersionMessage 的值,因为没有源历史记录。这就是为什么我还在 Job 级别使用变量 Build.SourceVersion 进行了测试。
我们不能在代理作业级别使用这两个变量,因为它还没有提取源,所以 Build.SourceVersionMessage 为空。您需要将其复制到管道中的每个步骤。这是我们的产品组团队确认的内容。
但是,我还是要说对不起。很抱歉我们的文档不太清楚,无法在代理工作级别中使用。
看来 Build.SourceVersionMessage
在 post 时只能在 steps
上解析。
这是一个工作示例,它在一个步骤中将值存储在一个变量中,并在下一个作业中使用它(可以是 deployment
)
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
中找到
我正在尝试将 Azure DevOps 设置为在消息未以给定文本开头时跳过 multi-stage pipeline 的阶段。
从examples documentation来看,我认为只是
- 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
任务不会 运行 基于提交消息 https://dev.azure.com/trajano/experiments/_build/results?buildId=110&view=results
env
的输出显示消息已正确传入
以防万一这是一个错误,我也在这里报告了它https://developercommunity.visualstudio.com/content/problem/697290/startswith-buildsourceversionmessage-variable-not.html
I am trying to set Azure DevOps to skip a stage if a message does not start with a given text.
如果我没理解错的话,你要的条件是如果消息匹配开头为maven-release-plugin
,则当前阶段会排队。
如果这样,你写的条件不对,我觉得你应该指定一下:
startsWith(variables['Build.SourceVersionMessage'], '[maven-release-plugin]')
正如我在管道上测试的那样:
而实际上这个变量的值是删除121321。这是结果:
如您所见,跳过阶段成功。我的逻辑是,Build.SourceVersionMessage
的值应该以othermessage
开头。但实际上,在我的管道中,它的值是Deleted 121321
。不匹配,所以跳过这个阶段。
(删除121321不仅是我的PR名称,我只是将commit message设置为默认PR名称。)
更新2:
虽然我的测试逻辑没有错,但是经过我用YAML复现等很多方法测试过,比如用Build.SourceVersion只能追源码拉。
是的,你是对的 Build.SourceVersionMessage 在工作级别没有价值。经过我的测试,它确实 null 在工作级别。
但是,不幸的是,这不是错误。这是实际设计的。
我们可以认为只有stage job开始执行才把source repos拉到本地,对吧?可以看到Checkout日志,它记录了拉取源文件的过程。
如果stage不执行,则source不会拉下来。而且,如果没有源拉取,服务器也将无法获取 Build.SourceVersionMessage 的值,因为没有源历史记录。这就是为什么我还在 Job 级别使用变量 Build.SourceVersion 进行了测试。
我们不能在代理作业级别使用这两个变量,因为它还没有提取源,所以 Build.SourceVersionMessage 为空。您需要将其复制到管道中的每个步骤。这是我们的产品组团队确认的内容。
但是,我还是要说对不起。很抱歉我们的文档不太清楚,无法在代理工作级别中使用。
看来 Build.SourceVersionMessage
在 post 时只能在 steps
上解析。
这是一个工作示例,它在一个步骤中将值存储在一个变量中,并在下一个作业中使用它(可以是 deployment
)
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
中找到