使用凭据签出 Jenkins Pipeline Git SCM? [英] Checkout Jenkins Pipeline Git SCM with credentials?
问题描述
我正在关注本教程:
node {
git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git'
...
}
但是它没有说明如何添加凭据.Jenkins 确实有特定的凭据"部分,您可以在其中定义用户 user&pass,然后获取 ID 以在作业中使用,但我如何在流水线指令中使用它?
However it doesn't tell how to add credentials. Jenkins does have specific "Credentials" section where you define user user&pass, and then get ID for that to use in jobs, but how do I use that in Pipeline instructions?
我尝试过:
git([url: 'git@bitbucket.org:company/repo.git', branch: 'master', credentialsId: '12345-1234-4696-af25-123455'])
运气不好:
stderr: Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
有没有办法在管道中配置凭据,或者我是否必须将 SSH 密钥放入 Jenkin 的 Linux 用户的 .ssh/authorized_keys 文件?
Is there a way configure the creds in pipeline, or do I have to put SSH-keys to Jenkin's Linux user's .ssh/authorized_keys file?
在理想情况下,我希望有一个用于管道作业和存储库密钥的存储库,然后启动 Docker Jenkins,并在那里动态添加这些作业和密钥,而无需在 Jenkins 控制台中配置任何内容.
In ideal world I'd like to have a repository for pipeline jobs and repo-keys, then launch Docker Jenkins, and dynamically add these jobs and keys there without having to configure anything in Jenkins Console.
推荐答案
您可以在管道中使用以下内容:
You can use the following in a pipeline:
git branch: 'master',
credentialsId: '12345-1234-4696-af25-123455',
url: 'ssh://git@bitbucket.org:company/repo.git'
如果您使用的是 ssh url,那么您的凭据必须是用户名 + 私钥.如果您使用 https 克隆网址而不是 ssh 网址,那么您的凭据应该是用户名 + 密码.
If you're using the ssh url then your credentials must be username + private key. If you're using the https clone url instead of the ssh one, then your credentials should be username + password.
这篇关于使用凭据签出 Jenkins Pipeline Git SCM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!