是否可以使用 Jenkins 管道进行 Git 合并/推送 [英] Is it possible to Git merge / push using Jenkins pipeline

查看:37
本文介绍了是否可以使用 Jenkins 管道进行 Git 合并/推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Jenkinsfile 创建 Jenkins 工作流程.我想要它做的就是监视开发"分支的变化.当发生变化时,我希望它 git tag 并合并到 master.我正在使用 GitSCM Step,但它似乎唯一支持的是 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 Jira 问题.

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.

因此,您似乎唯一的选择是实际执行标记/合并命令...但是,请注意,您仍然可以从一些 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.

这篇关于是否可以使用 Jenkins 管道进行 Git 合并/推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆