-
Bug
-
Resolution: Duplicate
-
Minor
-
Jenkins 2.138.1 (from docker)
plugins up-to-date as of 2018-10-02 17:00:00 UTC
sshagent + git checkout doesn't seem to work: the `SSH_AUTH_SOCK` env var disappears from the git process environment, and thus the ssh-agent is not available to ssh started by git...
Scenario:
- create a ssh key credentials `ssh-key`
- create a pipeline job with Jenkinsfile:
node { stage('Preparation') { sshagent (['my-ssh-key']) { sh 'printenv' sh 'ssh-add -l' git 'git@github.com:foo/bar.git' } } }
- run created job
Expected result:
ssh started by git finds the correct ssh key via the ssh agent.
Actual Result:
- git fetch fails : no valid ssh key found
- `ssh-add -l` works though, and shows the key added by `sshagent`
Other tests:
- `checkout` scm instead of `git` command: same behavior: it fails to find the key
- direct `sh 'ssh -vvv git@github.com'` works
More digging:
- configure a git wrapper as `git` tool in global jenkins config to observe what happens:
#!/bin/bash printenv >& /tmp/$$.git-env ssh-add -l >& /tmp/$$.git-ssh-add-list export GIT_TRACE=1 export GIT_SSH_COMMAND="ssh -vvv" git "${@}"
- run job again
Result:
- `ssh-add -l` fails: "Could not open a connection to your authentication agent."
- `printenv` shows `SSH_AUTH_SOCK` env var is not here, which explains why the ssh agent is not usable/used
So the remaining question is: why is the `SSH_AUTH_SOCK` env var removed when executing git commands ?
- duplicates
-
JENKINS-30600 git isn't run inside build container
-
- Open
-
[JENKINS-53877] sshagent + git checkout on local agent: ssh key not found
Description |
Original:
sshagent + git checkout doesn't seem to work: the `SSH_AUTH_SOCK` env var disappears from the git process environment, and thus the ssh-agent is not available to ssh started by git... Scenario: - create a ssh key credentials `ssh-key` - create a pipeline job with Jenkinsfile: {code:groovy} node { stage('Preparation') { sshagent (['']) { sh 'printenv' sh 'ssh-add -l' git 'git@github.com:foo/bar.git' } } } {code} - run created job Expected result: ssh started by git finds the correct ssh key via the ssh agent. Actual Result: - git fetch fails : no valid ssh key found - `ssh-add -l` works though, and shows the key added by `sshagent` Other tests: - `checkout` scm instead of `git` command: same behavior: it fails to find the key - direct `sh 'ssh -vvv git@github.com'` works More digging: - configure a git wrapper as `git` tool in global jenkins config to observe what happens: {code:bash} #!/bin/bash printenv >& /tmp/$$.git-env ssh-add -l >& /tmp/$$.git-ssh-add-list export GIT_TRACE=1 export GIT_SSH_COMMAND="ssh -vvv" git "${@}" {code} - run job again Result: - `ssh-add -l` fails: "Could not open a connection to your authentication agent." - `printenv` shows `SSH_AUTH_SOCK` env var is *not* here, which explains why the ssh agent is not usable/used So the remaining question is: why is the `SSH_AUTH_SOCK` env var removed when executing git commands ? |
New:
sshagent + git checkout doesn't seem to work: the `SSH_AUTH_SOCK` env var disappears from the git process environment, and thus the ssh-agent is not available to ssh started by git... Scenario: - create a ssh key credentials `ssh-key` - create a pipeline job with Jenkinsfile: {code:groovy} node { stage('Preparation') { sshagent (['my-ssh-key']) { sh 'printenv' sh 'ssh-add -l' git 'git@github.com:foo/bar.git' } } } {code} - run created job Expected result: ssh started by git finds the correct ssh key via the ssh agent. Actual Result: - git fetch fails : no valid ssh key found - `ssh-add -l` works though, and shows the key added by `sshagent` Other tests: - `checkout` scm instead of `git` command: same behavior: it fails to find the key - direct `sh 'ssh -vvv git@github.com'` works More digging: - configure a git wrapper as `git` tool in global jenkins config to observe what happens: {code:bash} #!/bin/bash printenv >& /tmp/$$.git-env ssh-add -l >& /tmp/$$.git-ssh-add-list export GIT_TRACE=1 export GIT_SSH_COMMAND="ssh -vvv" git "${@}" {code} - run job again Result: - `ssh-add -l` fails: "Could not open a connection to your authentication agent." - `printenv` shows `SSH_AUTH_SOCK` env var is *not* here, which explains why the ssh agent is not usable/used So the remaining question is: why is the `SSH_AUTH_SOCK` env var removed when executing git commands ? |
Assignee | Original: Mark Waite [ markewaite ] |
Link | New: This issue duplicates JENKINS-30600 [ JENKINS-30600 ] |
Resolution | New: Duplicate [ 3 ] | |
Status | Original: Open [ 1 ] | New: Resolved [ 5 ] |
Status | Original: Resolved [ 5 ] | New: Closed [ 6 ] |
I don't understand what you're trying to accomplish.
Can you explain further why you're not passing a Jenkins credential to the `git` Pipeline step rather than passing an empty string as the argument to ssh-agent and then adding the default private key?
Doesn't the ssh-add technique that you're using require that you place the private key into the ~/.ssh directory of each user that runs an agent? Passing a Jenkins credential will avoid that agent-specific configuration and will simplify the build script.
If you truly need fine-grained control of the git command, you might choose to place the git command inside an `sh` step that is wrapped by the ssh-agent command. If you've decided that you're not using Jenkins credentials to manage credentials, you can probably just as readily decide that you won't use the git plugin to manage checkout.
Note that I have not attempted the steps you've described, so I don't know if there is a way to accomplish what you're describing. I won't duplicate the bug report until later. I wanted to ask the clarifying questions before I invest the time to duplicate what you've described.