问题描述
我遵循:
node {
git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git'
...
}
然而,它并没有说明如何添加凭证。 Jenkins确实有特定的凭据部分,您可以在其中定义用户用户名和通行证,然后获取用于作业的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?
我尝试过:
I tried with:
git([url: '[email protected]:company/repo.git', branch: 'master', credentialsId: '12345-1234-4696-af25-123455'])
no运气:
no luck:
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.
有没有办法在管道中配置creds,还是必须将SSH-keys放到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 Console中配置任何东西。
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://[email protected]:company/repo.git'
如果你使用的是ssh url,那么你的凭证必须是用户名+私钥。如果您使用的是https clone url而不是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凭证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!