詹金斯(Jenkins):将git commit hash传递给下游作业 [英] Jenkins: pass git commit hash to a downstream job
问题描述
我有2个工作(A和B). 作业A指向URL-A上的git存储库. 作业B指向URL-B上的另一个git存储库.
I have 2 jobs (A and B). Job A points to a git repo at URL-A. Job B points to a different git repo, at URL-B.
一旦作业A完成并且稳定,它应该触发作业B并传递在作业A的构建中使用的git commit哈希.
Once job A finishes and is stable, it should trigger job B and pass the git commit hash that was used in job A's build.
最简单的方法是什么?
(作业B对应于从URL-B中检出的脚本,该脚本具有2个参数:git commit哈希和JAR工件,这些工件将包装在Docker映像中并推送到Docker中心)
(Job B corresponds to a script checked out from URL-B that has 2 parameters: a git commit hash and a JAR artifact that will be wrapped in a Docker image and pushed to Docker hub)
推荐答案
在作业B中,选中This project is parameterized
.定义一个String Parameter
,例如将Name设置为COMMIT
.在作业A中,将Post-build Actions
设置为Trigger parameterized build on other projects
. Project to build
是作业B的名称,Trigger when build is
为Stable
. Add Parameters
和Predefined parameters
,只需将COMMIT=$commit
放入其中. $commit
通常是作业A中定义的参数.您可以在作业B中添加其他预定义的参数,然后将值传递给作业A中的全部或部分参数.
In Job B, check This project is parameterized
. Define a String Parameter
, set Name to COMMIT
for example. In Job A, set Post-build Actions
with Trigger parameterized build on other projects
. Project to build
is Job B's name, with Trigger when build is
as Stable
. Add Parameters
with Predefined parameters
, in which you just put COMMIT=$commit
. $commit
is usually a paramter defined in Job A. You could add other predefined parameters in Job B and pass a value to all or some of them in Job A.
这篇关于詹金斯(Jenkins):将git commit hash传递给下游作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!