Jenkinsfile结帐:credentialsId很好,为什么sshagent不好?

时间:2018-02-01 21:03:14

标签: git jenkins ssh jenkins-plugins jenkins-pipeline

我的Jenkinsfilecheckout具有指定credentialsId的情况下正常工作:

checkout([$class: 'GitSCM',
          branches: [[name: '*/master']],
          doGenerateSubmoduleConfigurations: false,
          extensions: [],
          submoduleCfg: [],
          userRemoteConfigs: [[
              url: 'ssh://git@myhost.com/project/repo.git',
              credentialsId: 'my-jenkins-ssh-key-id'
          ]]
]);

Jenkinsfile包含在checkout 并具有相同凭据 时,我的sshagent根本不起作用:< / p>

sshagent(['my-jenkins-ssh-key-id']) {
    checkout([$class: 'GitSCM',
              branches: [[name: '*/master']],
              doGenerateSubmoduleConfigurations: false,
              extensions: [],
              submoduleCfg: [],
              userRemoteConfigs: [[
              url: 'ssh://git@myhost.com/project/repo.git'
          ]]
    ]);
}

这里的错误是什么:

[Pipeline] sshagent
[ssh-agent] Using credentials My Jenkins SSH key
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-DjRWGMTuxTdn/agent.125436
SSH_AGENT_PID=125438
$ ssh-add /path/to/private_key_3841979731983396728.key
Identity added: /path/to/private_key_3841979731983396728.key (/path/to/private_key_3841979731983396728.key)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] checkout
Cloning the remote Git repository
Cloning repository ssh://git@myhost.com/project/repo.git
 > git init /path/to/dir # timeout=10
Fetching upstream changes from ssh://git@myhost.com/project/repo.git
 > git --version # timeout=10
 > git fetch --no-tags --progress ssh://git@myhost.com/project/repo.git +refs/heads/*:refs/remotes/origin/* # timeout=5
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --progress ssh://git@myhost.com/project/repo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Jenkins可能相关的门票:

0 个答案:

没有答案