我的Jenkinsfile中有一个阶段,如下所示:
stage('Pull Source Code') {
steps {
script {
git branch: "master",
credentialsId: 'myCredentialId',
url: "${GIT_URL}"
}
sh 'git submodule update --recursive'
}
}
我想提供git git子模块更新步骤的凭据,因为它给出以下错误:
+ git submodule update --recursive
Cloning into 'submodule-destination-folder'...
fatal: could not read Username for 'https://tfsgit.mycompany.com': No such device or address
fatal: clone of 'https://tfsgit.mycompany.com/submodule-repo' into submodule path 'submodule-destination-folder' failed
有没有办法提供Jenkins凭证到git子模块更新?
其中一种方法是在UI中使用“高级子模块行为”
并在Jenkinsfile中使用以下代码
stage('Pull Source Code') {
steps {
checkout scm
}
}
你可以这样做:
stage('Pull Source Code') {
steps {
script {
git branch: "master",
credentialsId: 'myCredentialId',
url: "${GIT_URL}"
}
def submodulesList = sh(script:"git submodule init", returnStdout:true).split("\n")
for (String submodule : submodulesList) {
def submoduleName = submodule.split("'")[1]
def submoduleGitRepoUrl = submodule.split("\\(")[1].split("\\)")[0]
dir(submoduleName){
git url: submoduleGitRepoUrl, branch: "master", credentialsId: 'myCredentialId'
}
}
}
}