git - 如何为 jenkins git 插件指定 ssh key

标签 git jenkins ssh

我正在使用 git plugin ,据说集成了“Jenkins 凭据管理功能”:

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 的管道脚本”。

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

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

最佳答案

他们似乎同时添加了一些文档: https://jenkins.io/doc/pipeline/steps/git/

因此对于您的示例,以下内容应该有效:

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

关于git - 如何为 jenkins git 插件指定 ssh key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39634874/

相关文章:

git - git中有 "current branch"的字符吗?

git - Jenkins 权限被拒绝(公钥、gssapi-keyex、gssapi-with-mic、密码)

jenkins - Jenkinsfile管道中的SparseCheckout

emacs - 使用 ssh 配置的 emacs 中的 TRAMP 模式

git - 通过 intelliJ 添加远程 git repo

git - 检测 git rebase 上的冲突

Git 远程在 git init 后不显示 master 或 origin

selenium - net.thucydides.core.webdriver.UnsupportedDriverException : Could not instantiate class org. openqa.selenium.firefox.FirefoxDriver

ssh - 如何通过 SSH 调试 CircleCI VM?

java - 使用 Android 和 JSCH 获取 ConnectException : failed to connect to 192. 168.2.100(端口 22)ECONNREFUSED