将Jenkins Git轮询限制为一个分支
当前Jenkins管道作业设置为构建从Git签出的分支。要进行签出,我们使用SCM插件:将Jenkins Git轮询限制为一个分支,git,jenkins,jenkins-pipeline,npm-version,Git,Jenkins,Jenkins Pipeline,Npm Version,当前Jenkins管道作业设置为构建从Git签出的分支。要进行签出,我们使用SCM插件: triggers { pollSCM scmpoll_spec: '' } checkout( poll: true, scm: [$class: 'GitSCM', branches: [[name: 'refs/heads/develop']], userRemoteConfigs: [ [url: 'https://git-
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版本补丁
,更新package.json
文件,提交并在本地创建标记。然后我们将其推回到服务器端git存储库。为了阻止Jenkins启动另一个构建,我们使用选项进行推送,而post receive钩子忽略这些推送:
git push origin develop --follow-tags --push-option=nobuild
服务器上的post receive挂钩仅在用户按下时向Jenkins发送,因为他们不会使用以下选项:
"https://jenkins-server/git/notifyCommit?url=https://git-server/repo.git"
这一切都运行得非常好,然而,问题是当开发人员提交到功能
分支时,就会启动开发
分支的构建。我猜问题的原因如下:
develope
分支开发分支期间创建的标记
功能
分支分支上看到新标签,并开始构建
注意,我发现了另一个SO帖子:虽然文档中似乎没有,但为了再次寻找答案,我发现了这张詹金斯罚单:。似乎可以向URL添加一个额外的参数:
&branchs=
作为Gitpost receive
hook脚本的一部分,我可以找到分支名称并将其用作post的一部分:
https://jenkins-server/git/notifyCommit?url=https://git-server/repo.git&branches=develop
现在,这只会启动使用该特定分支的构建。虽然文档中似乎没有,但我再次寻找答案时遇到了这个Jenkins问题:。似乎可以向URL添加一个额外的参数:
&branchs=
作为Gitpost receive
hook脚本的一部分,我可以找到分支名称并将其用作post的一部分:
https://jenkins-server/git/notifyCommit?url=https://git-server/repo.git&branches=develop
这现在只会启动使用该特定分支的构建