简体   繁体   English

Jenkins 管道子模块身份验证

[英]Jenkins Pipeline Submodule Authentication

I have a repository that contains submodules.我有一个包含子模块的存储库。 These are developed in a publicly accessible GitHub repository.这些是在可公开访问的 GitHub 存储库中开发的。 My final deployment however is in a disconnected environment with mirrored GitHub repos in GitLab, which all require authentication.然而,我的最终部署是在一个断开连接的环境中,在 GitLab 中有镜像 GitHub 存储库,它们都需要身份验证。

My .gitmodules file contains URLs for the publicly available repos.我的.gitmodules文件包含公开可用的存储库的 URL。 I did some sed replacement in the job and can update them properly, but unfortunately, I'm then not able to authenticate, since it's a separate operation from the git url:.... step.我在工作中做了一些sed替换并且可以正确更新它们,但不幸的是,我无法进行身份验证,因为它是与git url:....步骤分开的操作。

I can clone the project with:我可以使用以下方法克隆项目:

git url: "git@my.gitlab.secure", branch: "master", credentialsId: "somecredentialid"

This doesn't update my submodules though unfortunately.不幸的是,这不会更新我的子模块。 And since I require authentication.而且因为我需要身份验证。

I also can clone using the checkout :我也可以使用checkout克隆:

      checkout([                                                            
        $class: 'GitSCM',                                                   
        branches: [[name: 'master']],                               
        doGenerateSubmoduleConfigurations: true,                            
        extensions: [[$class: 'SubmoduleOption',                            
          disableSubmodules: false,                                         
          parentCredentials: true,                                          
          recursiveSubmodules: true,                                        
          reference: '', trackingSubmodules: true]],                        
          submoduleCfg: [],                                                 
          userRemoteConfigs: [[credentialsId: 'somecredentialid',         
          url: 'git@my.gitlab.secure']]                                            
      ])                                                                    
    }                                                                       
  }

It isn't clear to me from the documentation what doGenerateSubmoduleConfigurations: true, and submoduleCfg: are for.文档中我不清楚doGenerateSubmoduleConfigurations: true,submoduleCfg:的用途。

I feel like the checkout way might be the solution, but I can't figure out how to update the .gitmodules to reflect the secured URLs for the submodules.我觉得checkout方式可能是解决方案,但我不知道如何更新.gitmodules以反映子模块的安全 URL。

This works for me in my case which is similar to what you trying to do here;就我而言,这对我有用,这类似于您在这里尝试做的事情; see if this helps.看看这是否有帮助。

checkout changelog: true, poll: true, scm: [
        $class: 'GitSCM',
        branches: [[name: "master"]],
        doGenerateSubmoduleConfigurations: false,
        extensions: [[$class: 'SubmoduleOption', recursiveSubmodules: true, parentCredentials: true], [$class: 'PruneStaleBranch']],
        submoduleCfg: [],
        userRemoteConfigs: [[name: 'origin', url: "Git ssh URL/${projectName}.git", credentialsId: 'Git credential']]
]

Having bashed my head against this a while too, here's what I found.我也为此苦恼了一段时间,这就是我的发现。

doGenerateSubmoduleConfigurations is exposed as scm.doGenerateSubmoduleConfigurations which suggests that it invokes SubmoduleCombinator . doGenerateSubmoduleConfigurations公开为scm.doGenerateSubmoduleConfigurations这表明它调用SubmoduleCombinator That doesn't look like what you want at all.这看起来根本不像你想要的。 The option should probably be (a) in an extension not the core plugin and (b) be called doGenerateSubmoduleCombinationMatrix or something.该选项可能应该是(a)在扩展中而不是核心插件中,并且(b)被称为doGenerateSubmoduleCombinationMatrix或其他东西。

submoduleCfg doesn't seem to get much obvious use in the git plugin. submoduleCfg在 git 插件中似乎没有得到太多明显的使用。 All I found for it was tests where it's empty.我找到的只是测试它是空的。

Functionality seems to have moved into SubmoduleOption .功能似乎已经转移到SubmoduleOption中。 This has method onCheckoutCompleted(...) that calls git.submoduleUpdate(...) .这有调用git.submoduleUpdate(...) onCheckoutCompleted(...)

So AFAICS the extensions entry for class SubmoduleOption is what you want.所以SubmoduleOption类 SubmoduleOption 的extensions条目就是你想要的。 And the docs are a bit special.而且文档有点特别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM