Issue
I am new to Jenkins and need some help..
I have 4 shell scripts : test1.sh, test2.sh, test3.sh and test4.sh
I want test2.sh to only run if test1.sh runs successfully and test4.sh to only run if test3.sh runs successfully. I also want test1.sh and test3.sh to run in parallel.
How could I achieve it in Jenkins?
I am using "Execute shell script on remote host using ssh" and "Conditional steps(multiple)" (just exploring). I have also set up keys so as to communicate with remote server.
Illustration using screen shot or other way would be helpful.
Thank you!
Solution
First, ensure that test1.sh and test3.sh return the standard success code when they succeed (0). Then the simple way, which works in any command line, not just Jenkins, is to use this command line:
((test1.sh && test2.sh) &) ; ((test3.sh && test4.sh) &)
Each pair of parentheses forms a subshell, double-amperands mean "if first succeeds then run second", and single ampersand mean "run in backgorund". So you get the equivalent of two backgrounded shells each running two scripts, which will exit if the first script doesn't return 0.
The Jenkins-specific solution is to have a node with two (or more) runners. Create two jobs, and tie both to that node. Each job runs a single shell, either test1.sh && test2.sh
, or test3.sh && test4.sh
.
Answered By - Paul Hicks
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)