詹金斯管道Git Push [英] Jenkins Pipeline Git Push
问题描述
在Jenkinsfile中是否有这样的阶段:
Is there as way to have a stage like so in a Jenkinsfile:
stage('Create Branch & Push Branch') {
steps {
script {
sh "git checkout -b release/${NEW_TAG}"
sh "git push --set-upstream
}
}
}
当前,这导致:
- git push --set-upstream原始版本/v1.0.3 致命:无法读取" https://github.com '的用户名:没有此类设备或地址 脚本返回了退出代码128
- git push --set-upstream origin release/v1.0.3 fatal: could not read Username for 'https://github.com': No such device or address script returned exit code 128
该存储库最初是使用以下方法在管道中克隆的:
The repository was originally cloned earlier in the pipeline using:
checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: 'develop']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CleanBeforeCheckout'], [$class: 'CleanCheckout'], [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'ci-github', url: 'https://github.com/my-org/my-repo.git']]]
该部分可以正常工作(克隆),大概是因为我可以为该步骤提供github的jenkins凭据ID.
That part works ok (the clone), presumably because I can supply this step with the jenkins credential id for github.
我是否有办法做同样的事情以将其推送回构建中较早克隆的存储库?
Is there a way for me to do the same to push back to a repo that was cloned earlier in the build?
推荐答案
我使用以下方法完成了这项工作:
I've made this work using:
withCredentials([usernamePassword(credentialsId: 'ci-github', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/my-org/my-repo.git')
}
阅读 https: //github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/push-git-repo/pushGitRepo.groovy 和使用SSH密钥的另一种方法似乎是:
An alternative approach using SSH keys appears to be :
sshagent(['credentiald-id-using-ssh-key'])
{
sh('git command or program calling git inside')
}
这篇关于詹金斯管道Git Push的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!