英文:
How to trigger azure devops build pipeline based on the commit message?
问题
How can I get a build triggered off of a specific commit?
我如何根据特定的提交触发构建?
I am building an Azure DevOps project. the project has both UI and Backend application codes. Both the codes are placed as a single project in GitLab. But different teams are working for UI and Backend.
我正在构建一个Azure DevOps项目。该项目同时包含UI和后端应用程序代码。这些代码都放在GitLab中的一个单一项目中。但UI和后端有不同的团队在进行开发。
I need to configure two build pipelines one for UI changes and one for backend changes.
我需要配置两个构建管道,一个用于UI更改,一个用于后端更改。
What I need is to trigger a specific pipeline based on the commit messages.
我需要根据提交消息来触发特定的构建管道。
ie; if a UI change is made, then the commit message will contain a keyword "UI_CHANGES" in it. The Azure DevOps should recognize this and trigger the UI build pipeline.
例如,如果进行了UI更改,那么提交消息中将包含关键字"UI_CHANGES"。Azure DevOps应该能够识别这一关键字并触发UI构建管道。
Can I make use of Git tags here or other possible ideas?
我可以在这里使用Git标签或其他可能的想法吗?
英文:
How can I get a build triggered off of a specific commit?
I am building an Azure Devops project. the project has both UI and Backend application codes. Both the codes are placed as a single project in GitLab. But different teams are working for UI and Backend.
I need to configure two build pipelines one for UI changes and one for backend changes.
What I need is to trigger a specific pipeline based on the commit messages.
ie; if a UI change is made, then the commit message will contain a keyword "UI_CHANGES" in it. The Azure DevOps should recognize this and trigger the UI build pipeline.
Can I make use of Git tags here or other possible ideas?
答案1
得分: 3
方法1:
当提交消息包含特定单词时构建(来源):
...
steps:
- bash: echo "Hello world"
condition: 包含(variables['Build.SourceVersionMessage'], 'HEY_DONTBUILD')
如果要反转逻辑,请在外部添加 not
,即:not(contains(...))
方法2:
另一种方法是在提交消息中包含 [ci skip]
(或其他特殊短语)以跳过该提交的构建。
方法3:
为不同的项目使用 only
标志(来源):
rspec:
script: ...
only:
variables:
- $CI_COMMIT_MESSAGE =~ /some-regexp/
英文:
Method 1:
Build when commit message contains a specific word (source):
...
steps:
- bash: echo "Hello world"
condition: contains(variables['Build.SourceVersionMessage'], 'HEY_DONTBUILD')
if you want to inverse logic, add not
outside, i.e.: not(contains(...))
Method 2:
Another way is to include [ci skip]
(or other special phrases in commit message) to skip the build for that commit.
Method 3:
Use only
flag for different projects (source):
rspec:
script: ...
only:
variables:
- $CI_COMMIT_MESSAGE =~ /some-regexp/
答案2
得分: 2
你不需要根据提交消息来运行流水线,你可以创建两个流水线,并在触发器中确定使用路径过滤器来决定哪个会在何时运行:
英文:
You don't need to run the pipeline according to the commit message, you can create two pipelines and in the trigger determine which will run when with the Path filters:
答案3
得分: 0
以下是已翻译的内容:
在我看来,某种形式的“路径过滤器”是你所需要的。
Azure DevOps拥有集成的“路径过滤器”,但这仅适用于托管在Azure DevOps上的存储库。
在你目前的情况下,我提出以下建议。
-
将你的存储库迁移到Azure DevOps 这是我认为最佳的解决方案,但如果你因某种原因必须坚持使用GitLab,则不适用
- 优点:你的存储库和流水线位于同一位置
- 缺点:你需要迁移存储库并设置新的成员资格等。
-
使用GitLab构建/发布 我对GitLab中的流水线不熟悉,所以我无法说这是否是可行的解决方案
- 优点:你的存储库和流水线位于同一位置,无需迁移
- 我不确定在GitLab中如何进行构建/发布(既不是优点也不是缺点)
-
将你的GitLab存储库镜像到Azure DevOps 你可以使用这个扩展不断地将你的存储库从GitLab镜像到Azure DevOps,并使用流水线的集成路径过滤器进行构建/发布
- 优点:你无需迁移,但可以使用Azure DevOps的流水线
- 缺点:你依赖于只“连接”两个独立的存储库的扩展。
-
将你的GitLab存储库连接到Azure DevOps,并在流水线中执行逻辑部分 我认为这是最不理想的解决方案,因为你必须在流水线中手动完成所有逻辑工作。
尽管如此,如果你对这个解决方案感兴趣,我建议进一步查看这个扩展。但它不像默认的路径过滤器那样方便。
更新
我仔细查看了这个扩展,我认为它不符合你的需求。对此我感到抱歉。尽管如此,你可以在不使用扩展的情况下连接到你的GitLab存储库。只需创建一个用于读取你的存储库的PAT,并在Azure DevOps中添加一个“其他git”的服务连接。
如前所述,你可以在流水线中完成构建的逻辑部分(这不是一个理想的解决方案)。
英文:
In my opinion some kind of "path filter" is what you need.
Azure DevOps has an integrated "path filter" but this works only for repos hosted on Azure Devops.
My proposals what you could do in your current situation.
-
Move your repository to Azure DevOps This is the best solution in my eyes but not applicable if you have to stick with GitLab for any reason
- Pro: You have repo and pipelines at the same location
- Con: You have to move the repo and set up new memberships etc.
-
Build/Publish with GitLab I am not experienced with pipelines in GitLab so I cannot say if this is a viable solution
- Pro: You have repo and pipelines at the same location and don't need to move
- I am not sure how building / publishing works with GitLab (neither pro nor con)
-
Mirror your GitLab repo to Azure DevOps You could use this extension to constantly mirror your repo from GitLab to Azure DevOps and build / publish with the pipeline's integrated path filter
- Pro: You don't need to move but can use the pipelines of Azure DevOps
- Con: You are dependent on the extension which only "connects" two independent repos.
-
Connect your GitLab repo with Azure DevOps and do the logical part within the pipeline I think this is the least favorable solution because you have to do all the logical stuff by hand within your pipeline.<strike> Nevertheless if you are interested in this solution I recommend a further look at this extension</strike>. But it is not as comfortable as the default path filter.
UPDATE
I just had a deeper look to this extension and I don't think that this fits your needs. Sorry for that. Nevertheless you can just connect to your GitLab repo without the extension. Just create a PAT for reading your repos and add a Service Connection for "Other git" in Azure DevOps.
As mentioned before you could do the logic of what to build within your pipeline (not favorable).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论