0

I changed the configuration in Jenkins to execute multiple build steps (Shell), the steps are:

1 - executes some prereq for my scripts

2 - the first part of the script

//I had to separate the executions to not consume all the resources from the VM I use to execute

3 - the rest of scripts

4 - the merge of all my xml files for the Reports.

An example of the step is:

Condition for the steps to be executed

export AUTOTEST_HOME="${WORKSPACE}"
export AUTOTEST_ADDRESS= IPaDD

cd "${AUTOTEST_HOME}/e2e_ui_tests/development_new_ui/"

ls -lah

if [ -L lib/node_modules ]; then
  unlink lib/node_modules
fi

if [ -L node_modules/node_modules ]; then
  unlink node_modules/node_modules
fi

#Running just install, without the post install scripts
npm install --ignore-scripts

#Library access symlink 
ln -s ../node_modules/ lib/node_modules

cd "${AUTOTEST_HOME}/e2e_ui_tests/development_new_ui/sharding/"

#Run the Prereq script to prepare the portal
./../lib/node_modules/protractor/bin/protractor 1_Conf_prereq.js

The problem is that since the step number 2 contains some failures (bugs found by the validations), Jenkins stops the build steps after its execution, ignoring the rest of it.

Is there a way to make it run till the very final step and then if it is the case, failing the job?

I tried to add the set +e at the top of the step to try to avoid the exit of the step, but didn't work (https://support.cloudbees.com/hc/en-us/articles/218517228-How-to-Ignore-Failures-in-a-Shell-Step)

" [12:02:55] E/launcher - Process exited with error code 1 Build step 'Conditional steps (multiple)' marked build as failure

[htmlpublisher] Archiving HTML reports...

"

PS: Protractor is correctly triggered for prereq and the specs, fails after the first problem is found by the scripts

Any idea how to solve this? thank you!

Alexandre
  • 432
  • 1
  • 3
  • 14

1 Answers1

1

1. Append || error1=true to your command that starts protractor, so you have

./../lib/node_modules/protractor/bin/protractor 1_Conf_prereq.js || error1=true

if tests fail it declares a variable error1=true

2. Your next challenge is that this variable is local and not available in your next script. Make it global as described here.

Essentially the approach here is create a text file where you store your variables, and then inject this variable to a global (environment) scope.

KEEP IN MIND the difference between echo AOEU=$(echo aoeu) > propsfile and echo AOEU=$(echo aoeu) >> propsfile. The first create a new file, the other one adds a new line in existing one (when you add second, third etc variable)

3. Do the same for your other step up until the final step

4. Inject your environment variable from the file you created in 2.

5. Add final step that chooses to fail the job or pass it

if [ $error1 || $error2 || $error3 ]
then
    exit 1
fi

It's been a while since I did this. Now I'm using pipeline syntax and docker images. So whatever I wrote maybe not exact and needs to be debbuged, but the approach is the same

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40