【问题标题】:Jenkins pipeline update file with build number and push to Git repoJenkins 管道更新文件,包含内部版本号并推送到 Git 存储库
【发布时间】:2022-10-12 22:34:29
【问题描述】:

在 Jenkins 管道中,我想在不同的 Git 存储库中使用新的内部版本号更新文件。

克隆 repo、更改文件、提交和推送更改的最佳方法是什么?

【问题讨论】:

    标签: git jenkins


    【解决方案1】:

    使用 shell 块是最简单的方法。

    stage('Change File'){
      steps{
            dir("newRepo"){
              sh '''
                  git clone YOUR_REPO .
                  echo $BUILD_NUMBER > file1.txt
                  git add file1.txt
                  git commit -m "Updates file1.txt with $BUILD_NUMBER"
                  git push
              '''
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      感谢@ycr,我终于能够解决它。

      withCredentials([usernamePassword(credentialsId: 'build.user', passwordVariable: 'pass', usernameVariable: 'user')]) {
          sh '''
              if cd tools-gitops; then git pull; else git clone http://git/Tools/tools-gitops; fi
              sed -i 's/"x\/x-support:.*"/"x\/x:'$BUILD_NUMBER'"/g' x-support.yml
              git commit -am "Updates x-support.yml with $BUILD_NUMBER"
              git push http://$user:$pass@git/Tools/tools-gitops
          '''
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-05
        • 1970-01-01
        • 1970-01-01
        • 2020-12-04
        • 1970-01-01
        相关资源
        最近更新 更多