ssh agent failing on pipeline script running on slave

1,288 ืฆืคื™ื•ืช
ืžืขื‘ืจ ืœื”ื•ื“ืขื” ื”ืจืืฉื•ื ื” ืฉืœื ื ืงืจืื”

Aitkiar Salaranโ€

ืœื ื ืงืจืื”,
23 ื‘ืžืื™ 2017, 6:54:1923.5.2017
ืขื“ 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โ€

ืœื ื ืงืจืื”,
24 ื‘ืžืื™ 2017, 11:38:4224.5.2017
ืขื“ 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โ€

ืœื ื ืงืจืื”,
24 ื‘ืืคืจืณ 2019, 7:25:0924.4.2019
ืขื“ Jenkins Usersโ€

Hi Salaran,

have you resolved this issue ?, I'm getting the same issue like wise any help :)
ื”ืฉื‘ ืœื›ื•ืœื
ื”ืฉื‘ ืœืžื—ื‘ืจ
ื”ืขื‘ืจ ืœื ืžืขื ื™ื
0 ื”ื•ื“ืขื•ืช ื—ื“ืฉื•ืช