我的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
有没有办法为git子模块更新提供Jenkins凭证?
答案 0 :(得分:1)
其中一种方法是在用户界面中使用“高级子模块行为”
,并在Jenkinsfile中包含以下代码
stage('Pull Source Code') {
steps {
checkout scm
}
}
答案 1 :(得分:0)
您可以这样做:
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'
}
}
}
}