Home > Back-end >  Jenkins does not finish steps upon build failure
Jenkins does not finish steps upon build failure

Time:04-27

I am implementing sanitizer tests for our C/CPP projects and I'm running into the following issue:

When asan, tsan or ubsan finds an issue the cmake build fails (which I expect it to, naturally). I am writing the build step to a log, including any errors/warnings found and use a python script to retrieve the required data from said log. When I run things locally via cmake/make I get the following:

I first run this:

#!/bin/bash
set -euo pipefail

ANALYSIS=${1}

cmake -Bbuild -DCMAKE_C_FLAGS="-fsanitize=${ANALYSIS}" -S .
make -C build all 2>&1 | tee MemTest/Logs/build.log

where analysis is the specific sanitizer I want to run, followed by a python script that checks for errors in build.log.

I introduced a use-after-free error and it catches it and returns the data I want in the script.

When running this similarly through Jenkins, Jenkins fails the build but does not execute the python script, like this:

stage('Sanitizer Test'){
            parallel {
                stage('Build Address Sanitizer'){
                    agent {
                        label 'mac'
                    }
                    steps{
                        script{
                            catchError (buildResult: 'FAILURE', stageResult: 'FAILURE') {
                                sh """
                                    ./buildGeneric.sh address
                                    ./RunTestApp.sh
                                    python3 ReadLog.py MemTest/Logs/build.log
                                    """
                                }
                            }
                        }
                    }

I know I might be able to use stash and unstash to run the python script anyway, but I am hoping for a way to continue the sh in Jenkins regardless of build failure.

CodePudding user response:

You can try and separate the sh command to 3 separated parts:

catchError (buildResult: 'FAILURE', stageResult: 'FAILURE') {
                            sh """
                                ./buildGeneric.sh address
                                """
                            }

catchError (buildResult: 'FAILURE', stageResult: 'FAILURE') {
                            sh """
                                ./RunTestApp.sh
                                """
                            }

catchError (buildResult: 'FAILURE', stageResult: 'FAILURE') {
                            sh """
                                python3 ReadLog.py MemTest/Logs/build.log
                                """
                            }

also see relevant examples here

CodePudding user response:

I have found (and solved) the issue I was facing. RunTestApp.sh and BuildGeneric.sh output to stderr, in order to log it in build.log I had to convert stderr to std out, like this:

        stage('Sanitizer Test'){
            parallel {
                stage('Build Address Sanitizer'){
                    agent {
                        label 'mac'
                    }
                    steps{
                        script{
                            catchError (buildResult: 'FAILURE', stageResult: 'FAILURE') {
                                sh """
                                    ./buildGeneric.sh address
                                    ./RunTestApp.sh 2>&1 | tee -a MemTest/Logs/build.log
                                    """
                                }
                            catchError (buildResult: 'FAILURE', stageResult: 'FAILURE') {
                                sh """
                                python3 ReadLog.py MemTest/Logs/build.log
                                """
                                }
                            }
                        }
                    }

Only thing left to do now is to make the Jenkins build fail somehow.

  • Related