使用jenkins管道作为代码从bitbucket私有存储库克隆

使用jenkins管道作为代码从bitbucket私有存储库克隆,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我使用jenikins管道作为代码来克隆位于私有bitbucket存储库(隐藏存储库)中的git项目。我使用此代码块在我的管道脚本中克隆项目 node { //checkout from master stage 'checkout' withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'MyID', usernameVariable: 'GIT_USERNAME', password

我使用jenikins管道作为代码来克隆位于私有bitbucket存储库(隐藏存储库)中的git项目。我使用此代码块在我的管道脚本中克隆项目

node {  
//checkout from master  
stage 'checkout'  
   withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'MyID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {  

      git url: 'https://paulrda@devMyCompany.org/stash/scm/test_automation.git' , branch: 'development'   
   }  
}  
“MyID”是凭据ID,我的用户名和密码正确。我将凭据保存在jenkins的全局凭据功能中。但是我在构建jenkins任务时遇到了这个错误

ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from https://paulrda@devMyCompany.org/stash/scm/test_automation.git at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:803) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1063) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1094) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:83) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:73) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47) at hudson.security.ACL.impersonate(ACL.java:221) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://paulrda@devMyCompany.org/stash/scm/test_automation.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: fatal: Authentication failed for 'https://paulrda@devMyCompany.org/stash/scm/test_automation.git/' at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1745) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1489) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:64) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:315) at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:801) 错误:获取远程回购“源”时出错 hudson.plugins.git.GitException:未能从中获取https://paulrda@devMyCompany.org/stash/scm/test_automation.git 位于hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:803) 位于hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1063) 位于hudson.plugins.git.GitSCM.checkout(GitSCM.java:1094) 位于org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109) 位于org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:83) 位于org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:73) 位于org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47) 位于hudson.security.ACL.impersonate(ACL.java:221) 位于org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44) 位于java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 在java.util.concurrent.FutureTask.run(FutureTask.java:266)处 位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 运行(Thread.java:745) 原因:hudson.plugins.git.git异常:命令“git fetch--tags--progresshttps://paulrda@devMyCompany.org/stash/scm/test_automation.git+refs/heads/*:refs/remotes/origin/*“返回的状态代码128: 标准: stderr:致命:身份验证失败'https://paulrda@devMyCompany.org/stash/scm/test_automation.git/' 位于org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1745) 位于org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1489) 位于org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:64) 位于org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:315) 位于hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:801) 在我的mac机器上,在我的paulrda帐户下,我可以使用jenkins管道脚本成功克隆我的项目,但当我切换到另一个帐户并运行jenkins时,我会收到此错误。我仍然不明白为什么我会犯这个错误。请提供此问题的解决方案

我的配置。
詹金斯版本:2.19.2
凭证插件:2.1.8
Git插件:3.0.0

Git客户端插件:2.1.0

它无法进行身份验证,因为您没有正确地将凭据传递给
Git
调用

由于您使用的是Git插件而不是shell命令,因此根本不需要使用带有凭据的
。您可以将
credentialsId
直接传递到
git
调用,如下所示:

stage('checkout') {
    git credentialsId: 'MyID', url: 'https://devMyCompany.org/stash/scm/test_automation.git', branch: 'development'
}

它无法进行身份验证,因为您没有正确地将凭据传递给
git
调用

由于您使用的是Git插件而不是shell命令,因此根本不需要使用带有凭据的
。您可以将
credentialsId
直接传递到
git
调用,如下所示:

stage('checkout') {
    git credentialsId: 'MyID', url: 'https://devMyCompany.org/stash/scm/test_automation.git', branch: 'development'
}

下面的错误消息显示,
的身份验证失败'https://ralles@dev.zaizi.org
,这是一个与上面代码不同的用户名(是否有意?)。但是检查用户名和密码。您还可以在
with credentials
步骤中使用
sh“echo$GIT_PASSWORD”
进行验证。因此,阅读整个错误消息可能不仅有助于您解决问题,还可以应用匿名化;-)下面的错误消息显示,
的身份验证失败'https://ralles@dev.zaizi.org
,这是一个与上面代码不同的用户名(是否有意?)。但是检查用户名和密码。您还可以在
with credentials
步骤中使用
sh“echo$GIT_PASSWORD”
进行验证。因此,阅读整个错误消息可能不仅有助于您解决问题,还可以应用匿名化;-)