简体   繁体   中英

Catching the error status while running scripts in parallel on Jenkins

I'm running two perl scripts in parallel on Jenkins and one more script which should get executed if the first two succeed. If I get an error in script1, script 2 still runs and hence the exit status becomes successful.

I want to run it in such a way that if any one of the parallel script fails, the job should stop with a failure status.

Currently my setup looks like

perl_script_1 &

perl_script_2 &

wait

perl_script_3

If script 1 or 2 fails in the middle, the job should be terminated with a Failure status without executing job 3.

Note: I'm using tcsh shell in Jenkins.

I have a similar setup where I run several java processes (tests) in parallel and wait for them to finish. If any fail, I fail the rest of my script.

Each test process writes its result to a file to be tested once done.
Note - the code examples below are written in bash , but it should be similar in tcsh .

To do this, I get the process id for every execution:

test1 &
test1_pid=$!
# test1 will write pass or fail to file test1_result

test2 &
test2_pid=$!

...

Now, I wait for the processes to finish by using the kill -0 PID command
For example test1 :

# Check test1
kill -0 $test1_pid

# Check if process is done or not
if [ $? -ne 0 ]
then
    echo process test1 finished
    # check results
    grep fail test1_result

    if [ $? -eq 0 ]
    then
        echo test1 failed
        mark_whole_build_failed
    fi
fi

Same for other tests (you can do a loop to test all running processes periodically).
Later condition the rest of the execution based on mark_whole_build_failed .

I hope this helps.

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