我正在使用 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/