Reputation: 1159
I am trying to create a Jenkins job that will trigger a shell script via the option Send files or execute commands over SSH in Jenkins. Following is the main part of my shell script:
#!/bin/bash
BRANCH=$1
cd /vm/deployment
git clone https://[email protected]/myuser/proj.git
#updating the common property files
cd /vm/deployment/swcm-properties
git reset --hard HEAD
#git pull ${BRANCH}
git fetch && git checkout ${BRANCH}
git pull
My problem here is that the execution fails as I am unable to pass the password and username for the repository for the clone to work.
I found an option to set the username and password as global credentials and made the following configurations:
I try to execute the following shell script which is saved in the server and I am getting the error ass below.
#!/bin/bash
git clone https://$uname:[email protected]/mysuer/myrepo.git
remote: Invalid username or password
fatal: Authentication failed for 'https://:@bitbucket.org/****/myrepo.git/'
What is the best approach to pass the username and password and trigger a git clone from a bitt bucket repository using Jenkins.
Upvotes: 1
Views: 1356
Reputation: 1327154
Another option, if you have only one credential to manage with BitBucket, would be (with the account used by Jenkins) to register your credentials in a Git credential helper (as described in Git Credential Storage)
That way, Git would automatically used the associated credentials, even in the context of a Jenkins job, since your master and agent are on the same machine.
Upvotes: 1
Reputation: 61
The best way to pull or build a code on Jenkins is to use plugins. "Bitbucket Plugin" can do the same for you. You can use credentials which created on Jenkins. You also can add a WebHook with this plugin.There are a lot of how-to online.
Upvotes: 0