Bitbucket HTTPS git clone failed via the pipeline script (Invalid username or password)

3,109 views
Skip to first unread message

pira...@gmail.com

unread,
Dec 19, 2016, 2:34:53 PM12/19/16
to Jenkins Users
Firstof, my company won't allow SSH connection to the bitbucket.org site and any other. So I have to use HTTPS for checkout scm in a multibranch pipeline project. It works perfect when the main repo is cloned by HTTPS and by using the bitbucket.org credential. But my main repo has a Jenkinsfile that will checkout another repo under the same project which contains a bunch of other groovy scripts. Then it threw out an error message and "git clone" will just fail. (If I change it to use SSH, it will work.)

The error message is:
"ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress https://bitbucket.org/myproject/scripts-repo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile.

My Jenkinsfile contains the following, and will check out the script-repo by HTTPS(As said SSH will work here):
fileLoader.fromGit('script_to_call', 'https://bitbucket.org/myproject/script-repo.git', 'master')

So how can I enable "using GIT_ASKPASS to set credentials" in this Jenkinsfile so that it will use the same bitbucket credential that was being used for the main repo check out?

thanks for anyone's help.



Here is the full logs when building:
Started by user J
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://bitbucket.org/myproject/mainrepo.git # timeout=10
Fetching upstream changes from https://bitbucket.org/myproject/mainrepo.git.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials bitbucket cred within pipeline domain
 > git fetch --tags --progress https://bitbucket.org/myproject/mainrepo.git +refs/heads/master
Checking out Revision 37e755bd6e51b66450ee39de9ad70ab6a8ba950c (master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 37e755bd6e51b66450ee39de9ad70ab6a8ba950c
 > git rev-list 37e755bd6e51b66450ee39de9ad70ab6a8ba950c # timeout=10
[Bitbucket] Notifying commit build result
[Pipeline] node
Running on master in /var/lib/jenkins/workspace/h-pipeline-example_master-QWL4DG3IFZJ6ZBQ2RI2QCTE4TJEXJ3XEKPIAKUG2LIUSXZOX2CVA
[Pipeline] {
[Pipeline] dir
Running in /var/lib/jenkins/workspace/h-pipeline-example_master-QWL4DG3IFZJ6Q2RI2QCTE4TJEXJ3XEKPIAKUG2LIUSXZOX2CVA/libLoader
[Pipeline] {
[Pipeline] deleteDir
[Pipeline] echo
Checking out https://bitbucket.org/myproject/script-repo.git, branch=master
[Pipeline] checkout
Cloning the remote Git repository
Cloning repository https://bitbucket.org/myproject/script-repo.git
 > git init /var/lib/jenkins/workspace/h-pipeline-example_master-QWL4DG3IFZJ6ZBQ2RI2QCTE4TJEXJKPIAKUG2LIUSXZOX2CVA/libLoader # timeout=10
Fetching upstream changes from https://bitbucket.org/myproject/script-repo.git
 > git --version # timeout=10
 > git fetch --tags --progress https://bitbucket.org/myproject/script-repo.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress https://bitbucket.org/myproject/script-repo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile.
fatal: Authentication failed for 'https://bitbucket.org/myproject/script-repo.git/'

Mark Waite

unread,
Dec 19, 2016, 2:50:33 PM12/19/16
to Jenkins Users
You'll somehow need to pass the credentialsId to the git (or checkout) task.  One way might be to assign the values extracted from the file you're reading to a groovy string, then pass the expansion of that string ( "${repository_url}" ) to the git command (or the checkout command) along with the credentialsId from the parent Jenkins job.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e055d665-c918-40fe-8c85-2fb5a70bb3e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ez pub

unread,
Dec 20, 2016, 1:46:39 PM12/20/16
to jenkins...@googlegroups.com
I know that if I add the crdentialsId, it will work, like:
fileLoader.fromGit('script_to_call', 'https://bitbucket.org/myproject/script-repo.git', 'master', xxxxx-xxxxx-xxxxxxx)
But I just don't want it in my source code on bitbucket, and there is no parent job.

I also tried to create the Global Environment Variable in Jenkins, but how can I pass it to fileLoader.fromGit()?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/_MTcjLNyPTU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtEu%2BTuBO-5X85-ipJyLdOEqVwYLCdEvFBnCiNvKTPP8cQ%40mail.gmail.com.

Mark Waite

unread,
Dec 21, 2016, 10:50:54 AM12/21/16
to jenkins...@googlegroups.com
I don't understand your objection to placing a credentials ID in your source code.  The ID does not contain any sensitive information.  It is a handle to the actual credential stored in Jenkins.

If you are really determined to not store the credentials ID, then you could parameterize the job and pass the credentials ID as a parameter.  You could pass an environment variable, then expand the environment variable in your pipeline job.  Refer to https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md in the "Managing the Environment" section for an example that shows how to read an environment variable in a pipeline job.

Mark Waite

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/_MTcjLNyPTU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAGY7CS_eTkp48ON1GtyQQ0xYyXdnhnh6Snfp4xOOXuLkZaqYiA%40mail.gmail.com.

pira...@gmail.com

unread,
Dec 27, 2016, 11:03:21 PM12/27/16
to Jenkins Users
Thanks for any of your advice, Mark!

Maybe I should make myself more clear:
I have 2 projects under my bitbucket account, I want to build project 1 (i.e to build a docker image with Dockerfile) but it will use the pipeline scripts in project 2. So I create a pipeline job for project 1 and use my credentials to check it out, but in my project 1 Jenkinsfile, I use the following line to call a script in my project 2 repo.   
 "fileLoader.fromGit('script_to_call', 'https://bitbucket.org/myproject/script-repo.git', 'master')

So the problem is that Jenkins used my credential and checked out project 1 without any issue, and then executed the pipeline in Jenkinsfile, but when it tried to check out project 2, it won't use the same credential:
.......
[Pipeline] checkout
Cloning the remote Git repository
Cloning repository https://bitbucket.org/myproject/scripts-repo.git
.....
 > git fetch --tags --progress https://bitbucket.org/myproject/scripts-repo.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress https://bitbucket.org/myproject/scripts-repo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: stderr: remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile. 
fatal: Authentication failed for 'https://bitbucket.org/myproject/scripts-repo.git/'
I am really confused which account profile it refers to. If I am adding the credential in Jenkinsfile as I mentioned in my earlier post, it will work.
 "fileLoader.fromGit('script_to_call', 'https://bitbucket.org/myproject/script-repo.git', 'master', 'xxxxxx-xxxx-xxx-xxxxxxx')

Just don't want to specify 2 times with the same credentials - there should be a way to pass it between the 2 repos when they are checked out in one building process.

thanks! 

Mark Waite

unread,
Dec 29, 2016, 5:17:40 PM12/29/16
to Jenkins Users
I guess you could declare the credentials in a variable and then reference the variable.  My pipelines which checkout from multiple repositories are configured to use credentials and they reference the credentials by name.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages