如何为jenkins git插件指定ssh密钥 [英] How to specify an ssh key for the jenkins git plugin

查看:109
本文介绍了如何为jenkins git插件指定ssh密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 git插件,该插件应该与"Jenkins凭证管理功能":

I am using the git plugin, which supposedly integrates wih the "Jenkins Credentials Management functionality":

凭证:使用Jenkins凭证管理功能,用于连接到存储库的凭证(除非允许匿名访问).使用的凭据类型取决于基础协议.对于SSH连接,仅支持私钥身份验证.

Credentials: Credentials to use to connect to the repository (unless anonymous access is allowed), using the Jenkins Credentials Management functionality. The type of credentials used depends on the underlying protocol. For SSH connections only private key authentication is supported.

太好了,"Jenkins凭据管理功能"正在为我工​​作:我能够运行来自SCM的管道脚本".

Great, the "Jenkins Credentials Management functionality" is working for me: I am able to run "Pipeline script from SCM".

那么,如何在git插件中使用这些凭据? git插件文档和网络中都没有示例.这是我的Jenkinsfile的相关部分,带有git步骤:

So, how do I use those credentials with the git plugin? There are no examples neither in the git plugin documentation, nor in the web. This is the relevant part of my Jenkinsfile, with the git step:

node {
    stage('Checkout') {
        git url: 'ssh://git@5.6.7.8:5999/my/repo.git', branch: 'wip'
    }
    ...
}

推荐答案

在此期间,他们似乎添加了一些文档: https://jenkins.io/doc/pipeline/steps/git/

They seem to have added some documentation in the meantime: https://jenkins.io/doc/pipeline/steps/git/

因此,对于您的示例,以下应该起作用:

So for your example the following should work:

checkout([$class: 'GitSCM', branches: [[name: '*/wip']],
    userRemoteConfigs: [[url: 'ssh://git@5.6.7.8:5999/my/repo.git',
    credentialsId: 'your-credentials-id']]])

这篇关于如何为jenkins git插件指定ssh密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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