[英]Prevent Jenkins job from launching additional jobs with git commit
I'm attempting to create a Jenkins pipeline which does the following steps at a high level:我正在尝试创建一个 Jenkins 管道,它在高级别执行以下步骤:
I want this pipeline to execute when a commit happens to specific branches.我希望在特定分支发生提交时执行此管道。 I have this working now, but the issue is when the job commits the new changes during the build (in step 5 above), it launches a new build and essentially enters an infinite loop.我现在有这个工作,但问题是当作业在构建过程中提交新的更改(在上面的步骤 5 中)时,它会启动一个新的构建并基本上进入一个无限循环。
I know this is working by design right now, but is there anyway way to prevent a new build job from executing?我知道这现在是按设计工作的,但是有没有办法阻止新的构建作业执行? Can I do something within the Jenkins pipeline to prevent the new commit from launching a new Jenkins job, or would this require a whole rework of the workflow?我可以在 Jenkins 管道中做一些事情,以防止新的提交启动新的 Jenkins 作业,还是需要对工作流程进行整个返工?
You can use generic-webhook-plugin ,您可以使用generic-webhook-plugin ,
For instance, GitHub webhooks in Jenkins are used to trigger the build whenever a developer commits something to the branch, in each webhook we have following info例如,Jenkins 中的 GitHub webhook 用于在开发人员向分支提交某些内容时触发构建,在每个 webhook 中我们都有以下信息
git repository name
branch which was changed
commit id
commit message
commit author
etc ...
To avoid loop避免循环
Here is the snippet that may help or change accordingly, it will not create look这是可能会有所帮助或相应更改的片段,它不会创建外观
#!/bin/bash
webhook_commit_id=$commit
commit_by_jenkins=commit_by_jenkins.txt
if [ ! -f $commit_by_jenkins ]
then
echo "creating local file name commit_by_jenkins.txt, please add this file to git ignore"
touch commit_by_jenkins.txt
fi
jenkins_commit=`cat commit_by_jenkins.txt`
if [ "${webhook_commit_id}" == "${jenkins_commit}" ]; then
echo "commit by jekins server, ignoring commit"
else
echo "commiting code from jenkins servver"
git add -A && git commit -m "commit by jenkins server" && git rev-parse HEAD > commit_by_jenkins.txt
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.