In our project we have a shell script which is to be sourced to set up environment variables for the subsequent build process or to run the built applications.
It contains a block which checks the already set variables and does some adjustment.
# part of setup.sh
for LIBRARY in "${LIBRARIES_WE_NEED[@]}"
do
echo $LD_LIBRARY_PATH | \grep $LIBRARY > /dev/null
if [ $? -ne 0 ]
then
echo Adding $LIBRARY
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBRARY
else
echo Not adding $LIBRARY
fi
done
i.e. it checks if a path to a library is already in $LD_LIBRARY_PATH
and if not, adds it.
(To be fair, this could be written differently (like here), but assume the script is supposed to achieve something which is very hard to do without calling a program, checking $?
and then either doing one thing or doing another thing).
The .gitlab-ci.yml
then contains
before_script:
- yum install -y <various packages>
- source setup.sh
but the runner decides to stop the before script the very moment $?
is non-zero, i.e. when the if-statement decides to add a path to $LD_LIBRARY_PATH
.
Now it is nice that the gitlab runner checks $?
after each line of my script, but here it'd be great if the lines in .gitlab-ci.yml
were considered atomic.
Is there a way to avoid the intermediate checks of $?
in a script that's sourced in .gitlab-ci.yml
?