Git 流程:如何在 Jenkins 中配置一键发布流程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29532101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git flow: How to configure a one-click release process in Jenkins?
提问by vikingsteve
We are using the standard git flow branching model (develop, master, release-, hotfix-, etc).
我们正在使用标准的 git 流分支模型(develop、master 、release-、hotfix-等)。
As part of our workflow, we would like to set up a "one-click" release via jenkins.
作为我们工作流程的一部分,我们希望通过 jenkins 设置“一键式”发布。
I was looking at the jgitflow-maven-plugin. Can I set up this plugin to do a one-click release from jenkins? If so, what are the configuration options?
我在看jgitflow-maven-plugin。我可以设置这个插件来从 jenkins 中一键发布吗?如果是这样,配置选项是什么?
In particular, can I do something like this?
特别是,我可以做这样的事情吗?
Jenkins Job
Maven goals: release-start release-finish -Dsomething -Delse
And is there a way tell it to automatically build from the latest -SNAPSHOT version, e.g. if the version is 1.2.3-SNAPSHOT
it would build release-1.2.3
.
有没有办法告诉它从最新的 -SNAPSHOT 版本自动构建,例如如果版本是1.2.3-SNAPSHOT
它会构建release-1.2.3
.
Otherwise, is there a maven plugin that builds releases according the git flow branching model(i.e. build from develop
and create a new release branch named release-x.y.z
).
否则,是否有根据 git flow 分支模型构建发布的 maven 插件(即从develop
并创建一个名为 的新发布分支release-x.y.z
)。
采纳答案by vikingsteve
We never found a way to get this to work via a plugin or maven goal in Jenkins.
我们从来没有找到通过插件或 Jenkins 中的 maven 目标来让它工作的方法。
Our solution ended up with a bash
script that did git flow release start <version>
, maven release process, git flow release finish <version>
and other things (git pull on develop
and master
at very start, git push
and slack notification at very end).
我们的解决方案结束了一个bash
脚本,做git flow release start <version>
,Maven的释放过程,git flow release finish <version>
和其他的东西(GIT拉的develop
和master
在一开始,混帐push
和松弛通知在最末尾)。
回答by gucce
Although this answer is one year old I'd like point out that meanwhile the jgitflow (v1.0-m5.1
) works with maven batch mode.
虽然这个答案是一年前我想指出同时 jgitflow ( v1.0-m5.1
) 与 maven 批处理模式一起使用。
So to release an artifact with just one commandyou can execute:
因此,要仅使用一个命令发布工件,您可以执行:
mvn --batch-mode jgitflow:release-start jgitflow:release-finish
You don'tneed to set developmentVersion
and releaseVersion
.
你并不需要设置developmentVersion
和releaseVersion
。
JGitFlow will use the current version minus the -SNAPSHOT
part as release version. Then it increments the least significant digit and adds -SNAPSHOT
again for the next development version.
Example1.0.0-SNAPSHOT
--> Release: 1.0.0
, next Development version: 1.0.1-SNAPSHOT
JGitFlow 将使用当前版本减去-SNAPSHOT
部分作为发布版本。然后它增加最低有效数字并-SNAPSHOT
为下一个开发版本再次增加。
示例1.0.0-SNAPSHOT
--> 发布:1.0.0
,下一个开发版本:1.0.1-SNAPSHOT
In order to configure a single click Jenkins release jobyou need to configure some things regarding Git.
为了配置单击 Jenkins 发布作业,您需要配置一些有关 Git 的内容。
Under Source Code Management > Git > Additional Behaviors
select
下Source Code Management > Git > Additional Behaviors
选择
Wipe out repository & force git clone
: just to make sure the workspace is cleanCheckout to specific local branch
: yourdevelop
branch.
Wipe out repository & force git clone
:只是为了确保工作区干净Checkout to specific local branch
: 你的develop
分行。
Finally, the release happens locally on your Jenkins server, so you want to push back the changesto your Git remote server.
最后,发布在您的 Jenkins 服务器本地发生,因此您希望将更改推送回您的 Git 远程服务器。
To accomplish this, the easiest way is to add a Post-build action
which executes the following bash command (the branch names may vary, I've used the JGitFlow default values):
要做到这一点,最简单的方法是添加一个Post-build action
执行以下 bash 命令的命令(分支名称可能会有所不同,我使用了 JGitFlow 默认值):
git push origin develop master --tags
NoteIf Jenkins is running on Windows you either have to execute a Batch script containing the same command (sometimes this doesn't work due to SSH issues with Windows) or configure the Git Publisher
Post-build action
accordingly.
注意如果 Jenkins 在 Windows 上运行,您要么必须执行包含相同命令的批处理脚本(有时由于 Windows 的 SSH 问题,这不起作用)或相应地配置Git Publisher
Post-build action
。
回答by dimapin
You can simply use the jenkins plugin M2 Release Pluginwith the release goals an options
-B -DautoVersionSubmodules=true jgitflow:release-start jgitflow:release-finish
您可以简单地使用 jenkins 插件M2 发布插件与发布目标和选项
-B -DautoVersionSubmodules=true jgitflow:release-start jgitflow:release-finish
回答by CSchulz
We ended up with starting the release via CLI on the client (because in Jenkins there is a bugstarting the release).
我们最终通过客户端上的 CLI 开始发布(因为在 Jenkins 中有一个错误开始发布)。
git flow release start -DautoVersionSubmodules=true
If you want to use the batch mode you need to specify developmentVersionand releaseVersion.
如果要使用批处理模式,则需要指定developmentVersion和releaseVersion。
Created a new job in Jenkins to build the release branch and use the M2 Release Pluginto release it finally:
在Jenkins中创建了一个新的工作来构建发布分支并最终使用M2发布插件发布它:
-B jgitflow:release-finish
If you use some custom profiles, you have to pass them additional via argumentscaused by a bug.
如果您使用某些自定义配置文件,则必须通过由错误引起的参数额外传递它们。
-Darguments=-Pprofile