小编典典

使用凭证结帐Jenkins Pipeline Git SCM?

jenkins

我正在关注本教程

node {
  git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git'
  ...
}

但是,它没有告诉您如何添加凭据。Jenkins确实具有特定的“凭据”部分,您可以在其中定义用户user&pass,然后获取要在作业中使用的ID,但是如何在管道指令中使用它呢?

我尝试过:

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文件中?

在理想的世界中,我想为管道作业和存储库提供一个存储库,然后启动Docker Jenkins,并在其中动态添加这些作业和键,而无需在Jenkins
Console中进行任何配置。


阅读 476

收藏
2020-07-25

共1个答案

小编典典

您可以在管道中使用以下内容:

git branch: 'master',
    credentialsId: '12345-1234-4696-af25-123455',
    url: 'ssh://git@bitbucket.org:company/repo.git'

如果您使用的是ssh网址,则您的凭据必须为用户名+私钥。如果您使用的是https克隆URL而不是ssh,则您的凭据应为用户名+密码。

2020-07-25