git jenkins构建完成后如何将更改推送到github?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19922435/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:17:17  来源:igfitidea点击:

How to push changes to github after jenkins build completes?

gitgithubjenkins

提问by Woland

I have a jenkins job that clones the repository from github, then runs the powershell script that increments the version number in the file. I'm now trying to publish that update file back to the original repository on github, so when developer pulls the changes he gets the latest version number.

我有一个 jenkins 作业,它从 github 克隆存储库,然后运行 ​​powershell 脚本来增加文件中的版本号。我现在正在尝试将该更新文件发布回 github 上的原始存储库,因此当开发人员提取更改时,他会获得最新版本号。

I tried using Git Publisher in the post build events, and I can publish tags with no issues, but it doesn't seem to publish any files.

我尝试在后期构建事件中使用 Git Publisher,我可以毫无问题地发布标签,但它似乎没有发布任何文件。

采纳答案by Woland

Found an answer myself, this blog helped: http://thingsyoudidntknowaboutjenkins.tumblr.com/post/23596855946/git-plugin-part-3

我自己找到了一个答案,这个博客有帮助:http: //thingsyoudidntknowaboutjenkins.tumblr.com/post/23596855946/git-plugin-part-3

Basically need to execute:

基本上需要执行:

git checkout master

before modifying any files

在修改任何文件之前

then

然后

git commit -am "Updated version number"

after modified files

修改文件后

and then use post build action of Git Publisherwith an option of Merge Results which will push changes to github on successful build.

然后使用Git Publisher 的构建后操作和合并结果选项,这将在成功构建时将更改推送到 github。

回答by Claus

The git checkout masterof the answer by Wolandisn't needed. Instead use the "Checkout to specific local branch" in the "Additional Behaviors" section to set the "Branch name" to master.

git checkout master对的由Woland答案是没有必要的。而是使用“附加行为”部分中的“结帐到特定本地分支”将“分支名称”设置为 master。

The git commit -am "blah"is still needed.

git commit -am "blah"仍然需要。

Now you can use the "Git Publisher" under "Post-build Actions" to push the changes. Be sure to specify the "Branches" to push ("Branch to push" = master, "Target remote name" = origin).

现在您可以使用“构建后操作”下的“Git Publisher”来推送更改。请务必指定要推送的“分支”(“要推送的分支”= master,“目标远程名称”= origin)。

"Merge Results" isn't needed.

不需要“合并结果”。

回答by Andrey Regentov

Actually, the "Checkout to specific local branch"from Claus's answer isn't needed as well.

实际上,"Checkout to specific local branch"也不需要来自克劳斯的回答。

You can just do changes, execute git commit -am "message"and then use "Git Publisher" with "Branch to push" = /refs/heads/master(or develop or whatever branch you need to push to), "Target remote name" = origin.

您可以进行更改,执行git commit -am "message"然后使用“Git Publisher”和“Branch to push”= /refs/heads/master(或开发或您需要推送到的任何分支),“目标远程名称”= origin。

回答by gayathri

I followed the below Steps. It worked for me.

我按照以下步骤操作。它对我有用。

In Jenkins execute shell under Build, creating a file and trying to push that file from Jenkins workspace to GitHub.

在 Jenkins 中,在 Build 下执行 shell,创建一个文件并尝试将该文件从 Jenkins 工作区推送到 GitHub。

enter image description here

在此处输入图片说明

Download Git Publisher Plugin and Configure as shown below snapshot.

下载 Git Publisher 插件并配置如下图所示。

enter image description here

在此处输入图片说明

Click on Save and Build. Now you can check your git repository whether the file was pushed successfully or not.

单击“保存并构建”。现在您可以检查您的 git 存储库文件是否已成功推送。