我在Jenkins 2.107.2。上创建了Multibranch管道。我想在克隆的存储库上执行git commit
,git push
等Git命令。
要向GitHub存储库进行身份验证,我已使用(https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin)在Jenkins中配置了我的用户凭据。我尝试了几种方法来使用这些凭据进行身份验证,但是它们会导致不同的错误。
第一种方法
stage('clone'){
steps{
checkout([$class: 'GitSCM', branches: [[name: '*/develop']],
userRemoteConfigs: [[url: 'https://github.com:xyz/demo.git']]])
}
}
stage('prepare release'){
steps{
sh "sed -i 's/-SNAPSHOT//g' pom.xml"
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'jenkins-user-for-demo-github', usernameVariable: 'GITHUB_DEMO_CREDENTIALS_USR', passwordVariable: 'GITHUB_DEMO_CREDENTIALS_PSW']]) {
sh "git add pom.xml"
sh "git commit -m 'release version set"
}
}
}
错误
***请告诉我你是谁。 跑 git config --global user.email“ you@example.com” git config --global user.name“您的名字”
第二种方法
stage('Checkout') {
steps{
git branch: 'develop', credentialsId: 'jenkins-user-for-demo-github', url: 'git@github.com:xyz/demo.git'
}
}
stage('prepare release'){
steps{
sh "sed -i 's/-SNAPSHOT//g' pom.xml"
sh "git add pom.xml"
sh "git commit -m 'release version set"
}
}
错误
原因:hudson.plugins.git.GitException:命令“ git fetch --tags --progress git@github.com:AbhayChandel / New-project.git + refs / heads / :refs / remotes / origin / ”返回的状态码128: 标准输出: stderr:主机密钥验证失败。 致命:无法从远程存储库读取。 请确保您具有正确的访问权限 并且存储库存在。
在解决这些错误时,我有以下问题: