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

Wol*_*and 43 git github jenkins

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

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

Cla*_*aus 42

git checkout master对的由Woland答案是没有必要的.而是使用"附加行为"部分中的"Checkout to specific local branch"将"Branch name"设置为master.

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

现在,您可以使用"Post-build Actions"下的"Git Publisher"来推送更改.务必指定要推送的"分支"("分支推送"=主,"目标远程名称"=原点).

不需要"合并结果".


Wol*_*and 36

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

基本上需要执行:

git checkout master
Run Code Online (Sandbox Code Playgroud)

在修改任何文件之前

然后

git commit -am "Updated version number"
Run Code Online (Sandbox Code Playgroud)

修改后的文件

然后使用Git Publisher的post build操作和 Merge Results选项,它将在成功构建时将更改推送到github.

  • @allprog - git发布者是否使用Git multiple scm插件?它看起来没有.在Git multiple scm的情况下,我们如何将更改推送到github?谢谢! (3认同)

And*_*tov 9

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

您可以执行更改,执行git commit -am "message"然后使用"Git Publisher"和"Branch to push"= /refs/heads/master(或开发或需要推送的任何分支),"Target remote name"= origin.


Gay*_*riB 7

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

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

在此输入图像描述

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

在此输入图像描述

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


Jas*_*ngs 5

设置 Global Jenkins 凭据后,您可以应用此步骤:

stage('Update GIT') {
  steps {
    script {
      catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
        withCredentials([usernamePassword(credentialsId: 'example-secure', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
            def encodedPassword = URLEncoder.encode("$GIT_PASSWORD",'UTF-8')
            sh "git config user.email admin@example.com"
            sh "git config user.name example"
            sh "git add ."
            sh "git commit -m 'Triggered Build: ${env.BUILD_NUMBER}'"
            sh "git push https://${GIT_USERNAME}:${encodedPassword}@github.com/${GIT_USERNAME}/example.git"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)