简体   繁体   中英

How to pass username and password of a bitbucket repository to a shell script triggered via jenkins

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://myuser@bitbucket.org/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:$pass@bitbucket.org/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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM