由于目前我们的构建需要从私有存储库克隆依赖项,我如何使用声明性/Scripted管道正确地克隆私有存储库?
def test_cloning() {
sshagent(["${SSH_KEY}"]) {
sh """
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" \
git clone -b dev git@github.com:/org/repo_eg.git repo_eg/
"""
}
}
pipeline {
agent none
environment {
SSH_KEY='sshkey'
}
stages {
stage('Build') {
parallel {
stage('static_agent') {
agent { label 'agent-1 }
steps {
test_cloning()
}
}
stage('static_agent') {
agent { label 'agent-2' }
steps {
test_cloning()
}
}
stage('swarm') {
agent { label 'swarm' }
steps {
sh 'mkdir ~/.ssh || true && ssh-keyscan github.com > ~/.ssh/known_hosts'
test_cloning()
}
}
}
}
}
post {
always {
node('agent-1') {
deleteDir()
}
node('agent-2') {
deleteDir()
}
}
}
}发布于 2018-10-12 19:31:04
希望这就是你要找的。在Jenkins服务器上创建一个以'jenkins‘用户身份登录的私钥/公钥对。使用公钥设置Git用户的配置文件(可以访问私有存储库)。将私钥添加到Jenkins服务器上的ssh-agent。
在管道脚本中使用SCM签出,以使用SSH url克隆存储库
https://jenkins.io/doc/pipeline/steps/workflow-scm-step/
Bitbucket repo示例:
checkout poll: false, scm: [$class: 'GitSCM', branches: [[name:
"refs/heads/${branchName}"]], doGenerateSubmoduleConfigurations: false, extensions:
[], submoduleCfg: [], userRemoteConfigs: [[url:"git@bitbucket.org:${repoName}.git"]]]https://stackoverflow.com/questions/52776964
复制相似问题