Dav*_*vid 1 git jenkins jenkins-pipeline
在Jenkinsfile中是否有这样的阶段:
stage('Create Branch & Push Branch') {
steps {
script {
sh "git checkout -b release/${NEW_TAG}"
sh "git push --set-upstream
}
}
}
Run Code Online (Sandbox Code Playgroud)
目前,这导致:
- git push --set-upstream原始版本/v1.0.3致命:无法读取“ https://github.com ”的用户名:没有此类设备或地址脚本返回退出代码128
该存储库最初是使用以下方式在管道中克隆的:
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']]]
Run Code Online (Sandbox Code Playgroud)
该部分可以正常工作(克隆),大概是因为我可以为该步骤提供github的jenkins凭据ID。
我是否有办法做同样的事情来回溯到构建早期克隆的存储库?
我使用以下方法完成了这项工作:
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')
}
Run Code Online (Sandbox Code Playgroud)
在阅读https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/push-git-repo/pushGitRepo.groovy和https://issues.jenkins-ci.org/browse/JENKINS-之后28335。
使用SSH密钥的另一种方法是:
sshagent(['credentiald-id-using-ssh-key'])
{
sh('git command or program calling git inside')
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7265 次 |
| 最近记录: |