Jenkins 如何在web钩子URL中动态传递git分支名称?
我在Jenkins中使用参数化的声明性下游作业。 在webhook期间,我需要将git_repo和git_分支作为参数传递 我在Gitlab存储库中定义了这个参数 示例Jenkins 如何在web钩子URL中动态传递git分支名称?,jenkins,continuous-integration,gitlab,jenkins-pipeline,jenkins-declarative-pipeline,Jenkins,Continuous Integration,Gitlab,Jenkins Pipeline,Jenkins Declarative Pipeline,我在Jenkins中使用参数化的声明性下游作业。 在webhook期间,我需要将git_repo和git_分支作为参数传递 我在Gitlab存储库中定义了这个参数 示例 https://myjenkins.com/job/myjob-builder-downstream/buildWithParameters?token=1qqq1f54ff88e373b3c0&git_repo=git@mygitlab:development/myproduct.git&git_branch=
https://myjenkins.com/job/myjob-builder-downstream/buildWithParameters?token=1qqq1f54ff88e373b3c0&git_repo=git@mygitlab:development/myproduct.git&git_branch=master
在webhook期间,我不知道如何将分支名称动态地传递给下游作业
提前感谢您的帮助。主要提供商(bitbucket、github和gitlab)不允许我们在静态webhook url注册步骤中使用此级别的参数化:
比特桶
Github
Gitlab
那么,解决方案是什么? 这些提供者为我们提供了另一种选择:Webhook post有效负载解释 它是如何工作的 当github(示例)调用我们的webhook url时,发送一个带有json的正文http,其中包含大量关于事件的信息:
- 分支机构名称
- 存储库名称
- 执行推送事件的用户名
- git提交消息
- 等
詹金斯插件 如果您使用一些jenkins插件,您可以使这个json解析无效。一个由供应商提供。对你来说。如果查看源代码,您将查看json解析
简易webhook插件 如果你与几个提供商合作,或者自定义插件对你没有帮助,你可以试试我的通用插件
https://myjenkins.com/project/myjob-builder-downstream/buildWithParameters?token=1qqq1f54ff88e373b3c0&git_repo=git@mygitlab:development/myproduct.git&git_branch=master
但有一些不同,我认为,更干净、更简单:
http://my_jenkins.com/easy-webhook-plugin-RDcd4y3LkDcMKKhG/?scmId=gitlab&jobId=hello_word_job
其中必须指明scmId(gitlab或bitbucket)和任何jenkins作业的id
当执行git push时,gitlab会将json发送到此url,我的插件会对其进行解析,并将一些标准参数转发给您的作业:
- 寄存名称
- 布兰奇纳姆
- 作者
- 事件消息
node {
echo 'New build detected with these incoming parameters: '+params
}
请跟随官方或随时与我联系