Dynamic Sleep time to execute next step in pipeline

14 views
Skip to first unread message

Ramesh Mari

unread,
Dec 1, 2019, 5:26:45 AM12/1/19
to Jenkins Users
Hello Guys,  

This is one tricky question, Please review the problem statement and advise me how to  get into further.


I have pipeline code which is combined of groovy and sh script. Refer the below sample one, based on that the line 4 code should be execute once ssh commend done in the target server completely which meant the triggered shell script takes time to complete in target server, so its depends on load in the script, by that we cannot put static sleep time after the line 3. what is the best way to achieve that.

node{
line 1 code
line 2 code
sh "ssh <usercredential>@<serverIP>: sh abc.sh or scb    // line 3
line 4 code
}

Mark Waite

unread,
Dec 1, 2019, 11:52:19 AM12/1/19
to Jenkins Users
If line 3 runs a program (shell script or otherwise) which does not spawn additional background processes, then that step will not return until line 3 has finished.  It would be synchronous.

Since you've indicated that the desired script actions have not completed when line 3 returns, I assume that means line 3 is requesting work be performed even after line 3 has returned.  It is asynchronous.  You're left with some possible choices:
  • Make line 3 be synchronous instead of asynchronous.  Line 3 won't return until its work is complete.  Depending on the nature of the call in line 3, this could be easy or very, very difficult
  • Guess an amount to wait and hope that it is long enough.  This is a common pattern and may be good enough in many cases.  It is not robust against wide variations in execution time or failures in the async step
  • Create a step that waits for the remote task or tasks to complete.  Have the remote task notify the waiting step that it is complete.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/28a8b3da-d8e3-4051-a4a3-7f6144b7ef83%40googlegroups.com.


--
Thanks!
Mark Waite

Ivan Fernandez Calvo

unread,
Dec 2, 2019, 11:23:41 AM12/2/19
to Jenkins Users
As Mark said spawn process in background in a Jenkins agent is a really bad idea.

Reply all
Reply to author
Forward
0 new messages