Console output of the pipeline Jenkins

Hi!
I’m some problems with the pipelines output. My pipeline has four steps, a their is to test de php code with grumhp. I do the image pull of the ubuntu on the docker with composer installed and make the test in the other step. The tests showed failures on the code but the step end with success. This pipeline is integrate with Gitlab and I need to block the merge button.

The code step bellow:


stages {
      stage('Pre Build') {
        steps {
          gitlabCommitStatus(name: 'Pre Build') {
            sh '''
              echo 'Setup Docker'

              if [ ! "$(docker ps -q -f name=company-jenkins)" ]; then
                      
                  if [ "$(docker ps -aq -f status=exited -f name=company-jenkins)" ]; then
                  
                      docker rm company-jenkins
                  fi
                  
                      docker run -d --name company-jenkins -v $WORKSPACE:/var/www/html company/magento2-php:8.1.4-ubuntu
              fi

              '''
          }
        }
      }
      
      stage('Run Tests') {
        steps {
          gitlabCommitStatus(name: 'Run Tests') {
            sh '''
            chmod 777 -R .pipelines/ && .pipelines/scripts/script-ci.sh
            '''
          }
        }
      }

      stage('Sonar') {
        steps {
          gitlabCommitStatus(name: 'Sonar') {
            script {
              def scannerHome = tool 'SonarScanner3.2.0.1227';
              withSonarQubeEnv('SonarDefault') {

              sh "${scannerHome}/bin/sonar-scanner"
              sh "cat .scannerwork/report-task.txt"
              }
            }
          }
        }

The error:

phpunit

PHPUnit 9.5.25 #StandWithUkraine

… 63 / 377 ( 16%)
… 126 / 377 ( 33%)
… 189 / 377 ( 50%)
… 252 / 377 ( 66%)
…E.EE… 315 / 377 ( 83%)
… 377 / 377 (100%)

Time: 00:03.658, Memory: 66.00 MB

There were 3 errors:

Step output

[Pipeline] }
[Pipeline] // gitlabCommitStatus
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // gitlabBuilds
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

this script isn’t setting the right exit code then.

I would recommend telling phpunit to output a junit file, then have jenkins parse that junit file. It’ll be a better experience as jenkins will say the build didn’t error, but tests didn’t pass, and even give you feedback which tests failed.

This is already setting, phpunit to output a junit file, the sonarqube read him. I would like to break the next step of the pipeline when there error on the php unit test.