Linux – script run through jenkins user gets killed

bashJenkinslinuxshell-scripting

In our jenkins build configuration we have the following shell commands (Execute shell) as the last step of our build process.

echo "$USER"
echo "Script executed from: ${PWD}"
git submodule update --init --recursive
if [ -f composer.json ]; then
    /usr/local/bin/composer install
fi
sed -i 's/phpunit --bootstrap/\/usr\/local\/bin\/phpunit \-\-bootstrap/g' runtest
./runtest --config unittest/configure.conf --coverage /var/lib/jenkins/workspace/coverage/

Everything used to work perfectly till our hard drive gets full and jenkins stopped building. After we cleaned the hard drive and tried building through jenkins again, the last step (Execute shell) failed to build with the following error:

[project] $ /bin/sh -xe /tmp/hudson815776538860444797.sh
+ echo jenkins
jenkins
+ echo 'Script executed from: /var/lib/jenkins/workspace/project'
Script executed from: /var/lib/jenkins/workspace/project
+ git submodule update --init --recursive
error: git-submodule died of signal 9
Build step 'Execute shell' marked build as failure

We tried running the shell commands as root and everything works as expected. However, once we run it as jenkins user, the process gets killed within few seconds.

[root@localhost project]# su -c "/bin/bash -x /tmp/hudson5288327457846724302.sh" -s /bin/sh jenkins
+ echo jenkins
jenkins
+ echo 'Script executed from: /var/lib/jenkins/workspace/project'
Script executed from: /var/lib/jenkins/workspace/project
+ '[' -f composer.json ']'
+ /usr/local/bin/composer install
Killed

I checked the system logs /var/log/messages but didnt find any clue. What can cause the issue and how we may troubleshoot this?

Best Answer

What is the state of your machine, specifically memory:

free -m

It could be the OOM killer. You would see logs. Try

grep -i “killed process” /var/log/messages