v0devil
v0devil

Reputation: 522

Jenkins and kill command in the script makes builds failed

Due some problems with the hanging of a python process (yandex-tank) during the build process in Jenkins (after which the build could not stop) i need to stop this problematic process with some additional kill command with timeout or using timeout command itself:

timeout $TIMEOUT yandex-tank-jmeter -i -o "jmeter.jmx=$WORKSPACE/$TEST_PLAN"

timeout sends default (15) kill signal, but after that the build goes to status FAILED.

Is there any workaround or special kill signal to make builds successful ?

Upvotes: 0

Views: 4329

Answers (2)

user1638152
user1638152

Reputation: 597

According to the Jenkins documentation for the "Execute shell" step:

By default, the shell will be invoked with the "-ex" option.

Therefore, Jenkins places all shell code into a shell script file, in the temp directory, something like /tmp/sh/jenkins45723947385985.sh and then executes it as follows:

/bin/sh -xe /tmp/sh/jenkins45723947385985.sh

This can be seen in the console output of the job.

The e option in -xe means that the shell will exit as soon as it has an error. To change this behaviour add a custom shebang line to the start of the Jenkins shell script such as

#!/bin/sh -x

Jenkins will no longer terminate as soon as an error occurs.

Upvotes: 0

r2d2
r2d2

Reputation: 192

Have you tried manual exit code overriding?

timeout $TIMEOUT yandex-tank-jmeter -i -o "jmeter.jmx=$WORKSPACE/$TEST_PLAN"; RES=$?
//If  the  command timed out, then RES equals 124.
...
//at the end of job scenario:
if [ $RES -eq 124 ]; then RES=0;
fi
exit $RES  

Upvotes: 4

Related Questions