jenkins를 통해 트리거된 쉘 스크립트에 bitbucket 저장소의 사용자 이름과 비밀번호를 전달하는 방법

jenkins를 통해 트리거된 쉘 스크립트에 bitbucket 저장소의 사용자 이름과 비밀번호를 전달하는 방법

Jenkins의 "SSH를 통해 파일 보내기 또는 명령 실행" 옵션을 통해 쉘 스크립트를 트리거하는 Jenkins 작업을 생성하려고 합니다. 내 쉘 스크립트의 주요 부분은 다음과 같습니다.

#!/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

내 문제는 복제 작업을 수행하기 위해 저장소의 비밀번호와 사용자 이름을 전달할 수 없기 때문에 실행이 실패한다는 것입니다.

사용자 이름과 비밀번호를 전역 자격 증명으로 설정하는 옵션을 찾아 다음을 구성했습니다.

구성

서버에 저장된 다음 셸 스크립트를 실행하려고 하면 다음 오류가 발생합니다.

#!/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/'

Jenkins를 사용하여 사용자 이름과 비밀번호를 전달하고 Bitbucket 저장소에서 git clone을 트리거하는 가장 좋은 방법은 무엇입니까?

답변1

이것이 Jenkins를 사용하여 선언적으로 구현한 방법입니다.

여기서 핵심은 을 사용하는 것입니다 URLEncoder.encode.

pipeline {
    environment {
        // bitbucketcredentials is stored at Jenkins Credentials Stored
        BITBUCKET_CREDENTIALS = credentials('bitbucketcredentials')
    }

    stages {
        stage('packaging git push para branch beta') {
            steps {  
                    script {
                        env.encodedPass=URLEncoder.encode(BITBUCKET_CREDENTIALS_PSW, "UTF-8")
                    }     
                    git push https://${BITBUCKET_CREDENTIALS_USR}:${encodedPass}@bitbucket.com/yourrepo.git branch

관련 정보