目前,我一直在试图从Jenkins中检索存储库的子模块。我的配置很好,我可以拉没有任何子模块的存储库就好了。
我还可以使用子模块提取repo的主要组件(在存储库名称中都使用SSH进行身份验证)。只有当我必须拉动子模块组件时才会出现问题。我正在运行最新版本的Jenkins,我在底部添加了一个部分,用于"高级子模块行为"。我选择了#34;递归更新子模块"在这里并多次运行构建无济于事。
当我尝试使用shell命令在底部添加额外的构建步骤时,存储库的更新也不起作用。当我在终端中的jenkins之外尝试这些命令时,这很好用。我总是在Jenkins得到的问题是:
FATAL: Command "git submodule update" returned status code 1:
stdout:
stderr: Cloning into 'thisismysubmodule'...
fatal: Authentication failed for 'https://git.thisismyrepo.com/scm/ap/thisismysubmodule.git/'
我发现了这个问题:https://issues.jenkins-ci.org/browse/JENKINS-20941但由于安全问题,我无法在底部使用建议的解决方案。这里有没有人有这个问题的经验或可能的解决方案?
答案 0 :(得分:13)
以下是使用SSH agent forwarding的解决方法。它对我来说很好。
<jenkins_home>/.ssh/config
并设置ForwardAgent yes
答案 1 :(得分:7)
现在已经发布了git-client和git-plug-in模块的Beta版本来解决这个问题。引用JIRA问题。
git客户端插件2.0.0-beta1已经发布了 实验更新中心。它包括git子模块认证, JGit 4.3,并且需要JDK 7.它至少需要Jenkins 1.625( 第一个版本要求JDK 7)
使用上面的附加行为部分下面有一个名为:
的选项使用来自父存储库的默认远程的凭据
当使用Jenkins 2.11和运行Windows服务器和从服务器的插件的beta版本时,这解决了我的问题。我没有检查过其他构建机器。 此外,您必须使用相同的身份验证方法,如果使用http,您必须将其用于子模块,如果使用SSH,则必须将此用于子模块,尝试混合方法将无法正常工作。
- 更新 -
不再需要测试版,请参阅以下页面:
Git Client Plugin
Git Plugin
答案 2 :(得分:2)
我刚遇到这个问题。对于使用最新版本的Jenkins(2016年12月发布)的用户,请尝试在git repo配置的Advanced sub-modules behaviours
部分启用此选项。
Use credentials from default remote of parent repository
答案 3 :(得分:1)
一种解决方案是在全局git配置文件中声明一个netrc凭证帮助,它将为来自git的任何http查询提供必要的凭据。
git config --global credential.helper "netrc -f C:/path/to/_netrc.gpg -v"
(确保使用与用于运行Jenkins的帐户相同的帐户)
我使用an encrypted netrc file,但您可以使用未加密的测试开始测试。
答案 4 :(得分:1)
考虑到我已经尝试了几乎所有可用的选项来实现这一点(SSH,.netrc,硬编码凭证......)唯一的选择是在'andreg的JENKINS-20941问题的底部提到的那个“:
是的,这个问题对我们来说也是一个真正的痛苦。我们唯一能得到的方式 它为我们的Stash / Jenkins设置工作就是创建一个只读用户 并在引用中对此用户的凭据进行硬编码 子模块。虽然做法不好,但所有用户都在使用git repo 已经拥有至少只读访问权限,所以我们并不觉得它也是如此 很多安全问题。例如在父repo .gitmodules文件中:
[submodule“shared-library”] path = shared-library url = https://username:password@stash.yourcompany.com/scm/project/shared-library.git
然后Jenkins作业选择了“递归更新子模块”。
答案 5 :(得分:1)
我实际上只是将它移动到shell命令,并在shell命令中告诉它使用哪个凭据助手,因为我在Windows上它是wincred:
git config --global credential.helper wincred
git submodule init
git submodule sync
git submodule update --init --recursive
答案 6 :(得分:0)
这个解决方案对我有用:
设置.gitmodule文件,以便它使用来自父仓库的ssh凭据:
[submodule "foo/repository"]
path = foo/repository
url = ssh://jenkins_build_monkey@domain.com/repository
这个解决方案有一个小小的警告。只要有人克隆了父回购,他们就需要将网址同步到他们有权访问的网址。用户第一次初始化子模块时,需要先编辑.gitmodules文件并更改URL:
[submodule "foo/repository"]
path = foo/repository
url = ssh://username@domain.com/repository
然后,在终端:
git submodule sync
git submodule init repository
git submodule update --remote repository
然后将网址更改回jenkins构建网址。除非您再次同步,否则子模块将使用与用户关联的URL。
2016年9月,Jenkins计划发布一项新功能,允许子模块共享父存储库的凭据。然后可以在.gitmodule中使用HTTP URL而不是ssh。
答案 7 :(得分:0)
我设法通过简单地在linux上添加带有凭据的.netrc文件来实现这一点。不是最安全的解决方案,但如果你需要让它快速运行,它将帮助你。
答案 8 :(得分:0)
如果您知道凭证名称,您也可以明确提供凭证,例如
stage ('Clone') {
steps {
checkout scm
withCredentials([sshUserPrivateKey(credentialsId: 'bitbucket_ssh', keyFileVariable: 'SSH_KEY')]) {
sh 'GIT_SSH_COMMAND="ssh -i $SSH_KEY" git submodule update --init'
}
}
}