我正在尝试创建一个Jenkins作业,通过在Jenkins中通过SSH发送文件或执行命令来触发shell脚本。以下是我的shell脚本的主要部分:
#!/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这里的问题是,执行失败了,因为我无法传递密码和用户名,以便存储库使克隆工作。
我找到了将用户名和密码设置为全局凭据的选项,并进行了以下配置:

当我试图执行保存在服务器上的以下shell脚本时,我会得到以下错误:
#!/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/'使用Jenkins传递用户名和密码并从Bitbucket存储库触发git克隆的最佳方法是什么。
发布于 2021-02-08 20:53:22
以下是我是如何使用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 branchhttps://unix.stackexchange.com/questions/569925
复制相似问题