将Jenkins Git轮询限制为一个分支



Out当前的Jenkins Pipeline作业设置为构建从Git签出的分支。要进行结账,我们使用SCM插件:

triggers {
pollSCM scmpoll_spec: ''
}
checkout(
poll: true,
scm: [$class: 'GitSCM',
branches: [[name: 'refs/heads/develop']],
userRemoteConfigs: [
[url: 'https://git-server/repo.git',
name: 'origin',
refspec: '+refs/heads/develop:refs/remotes/origin/develop',
credentialsId: 'XXX']
],
extensions: [
[$class: 'WipeWorkspace'],
[$class: 'CloneOption', honorRefspec: true, noTags: true, reference: '', shallow: false],
[$class: 'LocalBranch', localBranch: 'develop']
],
browser: [$class: 'GitList', repoUrl: 'https://git-server/gitlist/repo.git']
]
)

在构建过程中,有一个对npm version patch的调用,它更新package.json文件,提交并在本地创建一个标记。然后,我们将其推回到服务器端的git存储库。为了阻止Jenkins开始另一个构建,我们使用选项进行推送,后接收钩子忽略这些推送:

git push origin develop --follow-tags --push-option=nobuild

服务器上的postreceivehook只在用户推送时向Jenkins发布,因为他们不会使用选项:

"https://jenkins-server/git/notifyCommit?url=https://git-server/repo.git"

这一切都很好,然而,问题是当开发人员提交到feature分支时,develop分支的构建就开始了。我猜问题的原因如下:

  1. 提交/推送到develop分支
  2. 在构建develop分支期间创建的标记
  3. feature分支上的提交/推送
  4. Jenkins在开发branch时看到了新标签,并开始构建

因此,我正在寻找一种方法,要么强制Jenkins只考虑提交/推送到特定分支以触发特定构建。或者在考虑启动构建时,强制Jenkins忽略作为标记一部分的更改。

注意,我发现了另一个SO帖子:Jenkins git commit for specific branch triggers build jobs for other branch too

虽然文档中似乎没有,但在寻找答案时,我再次遇到了这个Jenkins票证:Jenkins-29574-notifyCommit分支参数被忽略。您似乎可以在URL中添加一个额外的参数:&branches=<branch-name>

作为Gitpost-receive钩子脚本的一部分,我可以找到分支名称,并将其用作POST:的一部分

https://jenkins-server/git/notifyCommit?url=https://git-server/repo.git&branches=develop

现在,这只会启动使用该特定分支的构建。

最新更新