How to refer to the private key generated by sshagent plugin?

79 views
Skip to first unread message

ZillaYT

unread,
Feb 15, 2019, 2:14:46 PM2/15/19
to Jenkins Users
I want to run a packer build in my Jenkins pipeline to create an AWS AMI. Packer needs an ssh key to connect to AWS, but we don't store the private key in our ephemeral Jenkins slaves that run in a Docker container. I therefore was thinking of using the sshagent plugin, and want to do this

sshagent(credentials: "some-creds") {
 
export SSH_KEY="/path_to_ssh_private_key"
  packer build create
-ami.json
}

Where the create-ami.json Packer file uses the SSH_KEY variable to set the ssh key.

I see this in the Jenkins console output

[Pipeline] sshagent
[ssh-agent] Using credentials some-creds (Bitbucket credentials)
[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-rTJZhA9qNK6L/agent.206
SSH_AGENT_PID=208
Running ssh-add (command line suppressed)
Identity added: /home/jenkins/workspace/Utilities/test-packer@tmp/private_key_614590059258028269.key (/home/jenkins/workspace/Utilities/test-packer@tmp/private_key_614590059258028269.key)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
[test-packer] Running shell script
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 208 killed;
[ssh-agent] Stopped.

But when I try to use 

export SSH_KEY=$WORKSPACE/test-packer@tmp/private_key_614590059258028269.key

the file isn NOT there, that is, packer can't connect via ssh. I run the same Packer file on my Mac locally and it works.

How can I make this work in a Pipeline script?

Edwin Makiuchi

unread,
Apr 4, 2019, 1:26:33 PM4/4/19
to Jenkins Users
Hi ZillaYT,

Can you let me know if you found a solution to this issue?

Thanks,
Edwin

ZillaYT

unread,
Apr 5, 2019, 11:00:58 AM4/5/19
to Jenkins Users
I have no solution. I saw your post that reference this one so hopefully someone will answer yours.
Reply all
Reply to author
Forward
0 new messages