im using jenikins pipeline as code to clone a git project which is in private bitbucket repository(stash repository). i used this code block to clone the project in my pipeline script.
node {
//checkout from master
stage 'checkout'
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'MyID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
git url: 'https://[email protected]/stash/scm/test_automation.git' , branch: 'development'
}
}
'MyID' is the credential ID and my username and password is correct.i save my credentials in global credentials feature in jenkins. but i get this error when i build the jenkins task.
ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from https://[email protected]/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://[email protected]/stash/scm/test_automation.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: fatal: Authentication failed for 'https://[email protected]/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)
In my mac machine under my paulrda account i can successfully clone my project using jenkins pipeline script but when i change to another account and run jenkins i get this error. still i cant understand why i get this error. please provide a solution to this problem.
my configurations.
Jenkins version : 2.19.2
Credentials Plugin : 2.1.8
Git plugin : 3.0.0
Git client plugin : 2.1.0
Authentication failed for 'https://[email protected]
, which is a different user name than your code above (by intention?). But check username and password. You could also usesh "echo $GIT_PASSWORD"
within thewithCredentials
step to verify. – StephenKing