我试图将基于GitHub PUSH的作业触发到某个分支。
我在没有时间表的情况下设置了JENKINS_URL/git/notifyCommit?url=REPO_URL
和Poll SCM
的webhook。
每个push
都会触发这项工作,但我无法过滤掉这个分支 - 我希望它只会在需要掌握的情况下发生。
答案 0 :(得分:0)
你必须为此目的使用git hook。
git hook将分支名称作为参数。
Hook code
强> #!/bin/sh
while read oldrev newrev refname
do
branch=`echo $refname | cut -d'/' -f3`
###
# Do whatever you want to do here with the branch name
###
done
答案 1 :(得分:0)
您可以参考以下答案:Trigger build in jenkins on specific branch in bitbucket
我刚刚发现Bitbucket不允许选择具体的 钩到推动任何分支。它只是调用所有钩子 开始所有詹金斯工作。
My solution was to create an specific file on my machine which Jenkins is installed and set a Bitbucket hook to this file. (e.g.
http:// {jenkins url}:{apache port} /check.php)
Note that this apache port is not the same of Jenkins', but Apache's. In my case, Jenkins was running at 8080 and Apache at 7777.
这样做是为了运行php脚本,但不是在Jenkins的目录中。
Since Bitbucket hook sends a json file, I was able to verify in check.php which branch has been pushed on. Reference: POST hook
管理
After the verification using a simple 'if', I just called the right url to start the right job with exec_curl, like: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, http://{jenkins url}:{jenkins port}/job/{job name}/build?token={job token}); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); And voilà.
答案 2 :(得分:0)