git 使用 Github 组织插件签出 Jenkins 中的子模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38921561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Checkout submodules in Jenkins with Github organisation plugin
提问by fabiim
I have a build job in Jenkins created by the Github Organization plugin. The Jenkinsfile
for this build checkouts the code using checkout scm
which is good as it figures out the correct branch/revision to checkout when building either PR triggered changes or pushes to the master branch.
我在 Jenkins 中有一个由Github Organization 插件创建的构建工作。在Jenkinsfile
使用代码此版本检出checkout scm
这是很好的,因为它无论是建设PR引起的变化或推到主分支时,计算出正确的分支/修订结帐。
How can I make this:
我怎样才能做到这一点:
node {
checkout scm
}
checkout submodules?
结帐子模块?
回答by Tuxlife
The solution with sh 'git submodule...'
works only for Repositorys without special authentication.
该解决方案sh 'git submodule...'
仅适用于没有特殊身份验证的存储库。
We use following solution in our set up:
我们在设置中使用以下解决方案:
node {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: true,
extensions: scm.extensions + [[$class: 'SubmoduleOption', parentCredentials: true]],
userRemoteConfigs: scm.userRemoteConfigs
])
}
回答by Ohad
In the Github organization plugin, add the advanced submodule behaviors.
在 Github 组织插件中,添加高级子模块行为。
And configure it like this:
并像这样配置它:
As @oeuftete pointed out, you also may need to add the "Checkout over SSH" behaviour (and provide a key credential) if the submodule(s) use the SSH protocol.
正如@oeuftete 指出的那样,如果子模块使用 SSH 协议,您可能还需要添加“通过 SSH 结账”行为(并提供密钥凭证)。
As documented here: https://wiki.jenkins.io/display/JENKINS/Git+Plugin
回答by Malcolm Crum
Change it to this:
改成这样:
node {
checkout scm
sh 'git submodule update --init'
}
Use bat
instead of sh
if Jenkins is running on Windows.
如果 Jenkins 在 Windows 上运行bat
,sh
则使用而不是。
回答by sys0dm1n
We had similar issue, Jenkin user is using https to pull from Github but the submodule is using SSH and we want to handle the pull requests with Jenkins. I did the below checkout stage hope it will help someone here:
我们有类似的问题,Jenkin 用户使用 https 从 Github 拉取,但子模块使用 SSH,我们想用 Jenkins 处理拉取请求。我做了以下结帐阶段,希望它能帮助这里的人:
stage('Checkout') {
if(env.BRANCH_NAME == "develop" || env.BRANCH_NAME == "master") {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false],
[$class: 'CleanBeforeCheckout'],
[$class: 'CleanCheckout']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'jenkins-ssh',
url: '[email protected]:<AccountName>/<RepoName.git>']]
])
}
else if (env.CHANGE_ID) {
checkout([
$class: 'GitSCM',
branches: [[name: "FETCH_HEAD"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false],
[$class: 'CleanBeforeCheckout'],
[$class: 'CleanCheckout']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'jenkins-ssh',
refspec: "+refs/pull/${CHANGE_ID}/head:refs/remotes/origin/${BRANCH_NAME} +refs/heads/${CHANGE_TARGET}:refs/remotes/origin/${CHANGE_TARGET}",
url: '[email protected]:<AccountName>/<RepoName.git>']]
])
}
}
Maybe there is an easier way to do it, I would be happy to hear from you :-)
也许有更简单的方法可以做到,我很高兴收到您的来信:-)