【发布时间】:2022-10-12 22:34:29
【问题描述】:
在 Jenkins 管道中,我想在不同的 Git 存储库中使用新的内部版本号更新文件。
克隆 repo、更改文件、提交和推送更改的最佳方法是什么?
【问题讨论】:
在 Jenkins 管道中,我想在不同的 Git 存储库中使用新的内部版本号更新文件。
克隆 repo、更改文件、提交和推送更改的最佳方法是什么?
【问题讨论】:
使用 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
'''
}
}
}
【讨论】:
感谢@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
'''
}
【讨论】: