简体   繁体   中英

Running shell script commands sequentially in Jenkins

In Jenkins, I have created a job which runs many shell script commands:

command1
command2
...etc

command1 is an ssh command which calls a shell script file on another server machine. I have to wait until it is finished, and AFTER it, command2 should come.

So, how can I make sure that the script file on the other machine, started by command1 , has already finished its jobs, when in the Jenkins job the next command ( command2 ) is started?

Or, alternatively,how can I make sure that command2 won't be started until the shell script on the other machine (started by command1 ) has already finished?

You can check out " How to send many commands to shell and wait for the command behind ends " in order to chain commands and wait for their completion.

When you execute a command through an ssh session, you might have to wrap that command in a script able to loop/wait for the command completion.
See an example in " How can I make ssh wait until the command exits? ".
Or (a simpler wraper): How do I know when a command run over ssh has finished?

#/bin/bash
$@ 
echo "==== Command Output Finished ===="

look for the string ==== Command Output Finished ==== in your I/O routines to determine where the boundary between command outputs are. Or you can try isolate those commands in their own Jenkins shell build step.
(Not a different job, just a different build step within the same job)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM