ssh agent failing on pipeline script running on slave

1,289 views
Skip to first unread message

Aitkiar Salaran

unread,
May 23, 2017, 6:54:19 AM5/23/17
to Jenkins Users
Hi,

I have pipeline job that uses ssh agent step to set up credentials to connect to git repository and clone it. When i execute the job on the master jenkins, it runs flawlesly. When run it on a slave it fails because ssh agent closes before the git clone.

This is an example of the code that produces the error:

node
{
   
def credentials = 'somecredentials'
    sshagent
(credentials: [credentials])
   
{
        sh
( script:"""
        rm -rf common_jenkins_jobs
        git clone ssh://gito...@somerepos.git
        """
)
   
}
}

node
( "ci-server-slave" )
{
   
def credentials = 'somecredentials'
    sshagent
(credentials: [credentials])
   
{
        sh
( script:"""
        rm -rf common_jenkins_jobs
        git clone ssh://gito...@somerepos.git

        """
)
   
}
}

The first block runs on the master node and the seccond on the slave. Examing the execution logs of the first block you can see the sequence:
  1. ssh-agent start
  2. rm
  3. git
  4. ssh-agent stop

but the part that runs on the slave shows the sequence:

  1. ssh-agent start
  2. ssh-agent stop
  3. rm
  4. git

leaving the git clone out of the ssh-agent environment and failing due to lack of crecedentials.


I attached the log of the second node on a simpler test where the sh step only runs an ls ltr command. There you can clearly see that the ls command runs after the ssh-agent ends.


¿ Can this behaviour be part of some missconfiguration on my part or is a bug on the ssh agent step ?



simpletext.txt

Aitkiar Salaran

unread,
May 24, 2017, 11:38:42 AM5/24/17
to Jenkins Users
I'll answer my self.

The problem was not in the ssh-agent step but on the knwon_hosts file. Since it was the first connection to the git repos from that slave machine, the knwon_hosts file in the slave didn't contain the keys for the remote git server and the checkout fails. I supouse that the log lines that trick me in to think there was something wrong with the step where n the wrong order because of asynchronous logging or something similar.

Thanks anyway

forp...@gmail.com

unread,
Apr 24, 2019, 7:25:09 AM4/24/19
to Jenkins Users

Hi Salaran,

have you resolved this issue ?, I'm getting the same issue like wise any help :)
Reply all
Reply to author
Forward
0 new messages