gpt4 book ai didi

git - Jenkins 管道Git Push

转载 作者:行者123 更新时间:2023-12-03 15:08:39 28 4
gpt4 key购买 nike

是否有一种在Jenkinsfile中具有类似阶段的方式:

stage('Create Branch & Push Branch') {
steps {
script {
sh "git checkout -b release/${NEW_TAG}"
sh "git push --set-upstream
}
}
}

目前,这导致:

  • 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


该存储库最初是使用以下方法在管道中克隆的:
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。

我是否有办法做同样的事情以回退到构建早期克隆的存储库?

最佳答案

我已经使用以下工具完成了这项工作:

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.groovyhttps://issues.jenkins-ci.org/browse/JENKINS-28335之后。

使用SSH key 的另一种方法似乎是:
sshagent(['credentiald-id-using-ssh-key']) 
{
sh('git command or program calling git inside')
}

关于git - Jenkins 管道Git Push,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53325544/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com