Git是否可以使用Jenkins管道合并/推送 [英] Is it possible to Git merge / push using Jenkins pipeline
问题描述
我正在尝试使用Jenkinsfile创建Jenkins工作流.我要做的就是监视'develop'分支中的更改.当发生更改时,我希望它进行git标签并合并到master.我正在使用GitSCM步骤,但它似乎唯一支持的就是git clone.我不想掏出钱来做标记/合并,但我看不出有什么办法.有人知道这是否可能吗?我在我的Git服务器上使用BitBucket(本地).
I am trying to create a Jenkins workflow using a Jenkinsfile. All I want it to do is monitor the 'develop' branch for changes. When a change occurs, I want it to git tag and merge to master. I am using the GitSCM Step but the only thing that it appears to support is git clone. I don't want to have to shell out to do the tag / merge but I see no way around it. Does anyone know if this is possible? I am using BitBucket (on-prem) for my Git server.
推荐答案
目前无法实现,因为以前负责标记/合并/推送自由式作业的插件GitPublisher
尚未更新为与Jenkins管道兼容.您可以在 GitPublisher吉拉问题
It is not possible at the moment because GitPublisher
plugin, the plugin previously responsible for tagging/merging/pushing in freestyle jobs, has not been updated to be compatible with Jenkins pipelines. You can follow that issue on both the pipeline plugins compatibility page and the dedicated GitPublisher Jira issue.
因此,您似乎唯一的选择是实际上掏空您的tag/merge命令.但是,请注意,您仍然可以从一些Jenkins内置功能中受益,例如在您的Git存储库中使用凭据,这使得根据您的需求进行标记/合并非常简单.
So it seems the only option you have is to actually shell out your tag/merge commands... However, note that you can still benefit from some Jenkins built-in capabilities such as the use of credentials for your Git repo, which make it pretty straightforward to then tag / merge following your needs.
结帐示例:
git url: "ssh://jenkins@your-git-repo:12345/your-git-project.git",
credentialsId: 'jenkins_ssh_key',
branch: develop
然后,标记/合并/推送将非常简单:
Then the tag / merge / push will be pretty straightforward :
sh 'git tag -a tagName -m "Your tag comment"'
sh 'git merge develop'
sh 'git commit -am "Merged develop branch to master'
sh "git push origin master"
我希望有一天GitPublisher可以在管道兼容的版本中发布,但现在应该可以采用这种解决方法.
I hope that one day GitPublisher will be released in a pipeline-compatible version, but for now this workaround should do.
这篇关于Git是否可以使用Jenkins管道合并/推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!