Jenkins-与父回购不同的Git子模块凭证 [英] Jenkins - Git Submodule Credentials Different from Parent Repo

查看:329
本文介绍了Jenkins-与父回购不同的Git子模块凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins被用于从具有Git子模块的Git仓库中构建工件.子模块与父项目不在同一个仓库中,甚至不在同一个端点上.问题在于,父凭证检查良好,因为凭证ssh密钥A与主/父凭证相关联,但并不奇怪,该子模块失败,因为凭证ssh密钥B与Jenkins的存储库无关的观点.

Jenkins is being used to build an artifact from a Git repo that has a Git submodule. The submodule(s) are not in the same repo or even at the same endpoint as the parent project. The problem is that parent repo checks out fine because the credential, ssh key A, is associated with the main/parent repo but, not surprisingly, fails on the submodule because the credential, ssh key B, is not associated with the repo from Jenkins' point of view.

令人惊讶的是,詹金斯没有更好的现成的Git子模块支持.是时候贡献力量了.

It's surprising that Jenkins does not have better out-of-the-box support for Git submodules; time to contribute.

  1. 是否可以为单个Git存储库存储多个凭证?
  2. 如果答案是否定的,Jenkins为什么在高级子模块行为下提供选项,使用来自父存储库的默认远程的凭据,如下所示? /li>
  3. 还有什么其他方法可以处理具有不同凭据的Jenkins和Git子模块?
  1. Is there a way to store multiple credentials for a single Git repo?
  2. If the answer is no, why does Jenkins, under Advanced sub-modules behaviours provide the option to Use credentials from default remote of parent repository as shown below?
  3. What other approach is there for dealing with Jenkins and Git submodules with different credentials?

在Docker计算机上(本地)运行Jenkins

Running Jenkins on Docker Machine (Locally)

在CentOS(生产)上运行Jenkins

Running Jenkins on CentOS (Production)

Jenkins版本:2.60.2(两者)

Jenkins Version: 2.60.2 (both)

Git插件版本:3.6.4(两者)

Git Plugin Version: 3.6.4 (both)

推荐答案

是的,这很容易做到.您可以创建发布/私有密钥对并将其设置为 github部署密钥(如果您使用的不是git hub,则作为您使用的任何键集).您可以将其添加为Jenkins凭据(前提是您已安装了凭据插件).

Yes this is easily done. You can create pub/private key pair and set it up as a github deploy key (if you are using git hub if not, then as a key set in whatever you do use). You can add that as a Jenkins credential (provided you have the credentials plugin installed).

Username: git@github.com
Private Key:  the private key for that key set
Passphrase:  whatever passphrase you used
ID: aws-jenkins-github-deploykey (just an example name)
Description: some useful text

该ID映射到下面的 credentialsId

The ID maps to the credentialsId below

checkout changelog: true, poll: false, scm: [$class: 'GitSCM',
     branches: [[name: "branch name, commit sha, or tag/tagname" ]],
     userRemoteConfigs: [[
     credentialsId: 'aws-jenkins-github-deploykey',
     url: 'git@github.com:myorg/myrepo.git']]]

运行此流水线代码时,它将在分支中检出存储库,提交等到工作目录.您还可以指定目录.

When this Pipeline code runs, it checks out the repo at the branch, commit, etc to the working directory. You can also specify the directory.

因此,您可以使用它来签出一堆仓库并为其使用特定分支.

So you can use this to checkout a bunch of repos and use specific branches for them.

这篇关于Jenkins-与父回购不同的Git子模块凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆