我的Jenkinsfile
在checkout
具有指定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可能相关的门票: