Home > other >  Null pointer exception in Jenkins pipeline when Jacoco plugin is used
Null pointer exception in Jenkins pipeline when Jacoco plugin is used

Time:12-15

Jenkins pipeline errors out with Null pointer exception when I am using Jacoco plugin. If I comment out the Jacoco step from Jenkinsfile then there is no error thrown. The log file in Jenkins indicate that the error is thrown after the End of Pipeline. Below is the log message and the Jenkins file details. Any idea why this error is thrown?

[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.NullPointerException
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:87)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:70)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

Jenkins file ....

pipeline{

agent any

    stages{

        stage('Git clone project'){
            steps{
                git branch: 'sandbox',url:'https://<repo url>'
                sh 'git branch -a'
            }
         
        }

        stage('Test TMS'){
            steps{
                    dir('TestManagementService'){
                          sh 'pwd'
                          sh './gradlew test'
                          step(
                            jacoco(
                                execPattern: '**/build/jacoco/**.exec',
                                classPattern: '**/build/classes/java/main',
                                sourcePattern: '**/src',
                                inclusionPattern: 'com/testMgmt/**',
                                )
                          )
                    }
            }
            
            post{
                always{
                    junit '**/build/test-results/test/TEST-*.xml'
                }
            }
        }
       
    }// end of stages

}

CodePudding user response:

The issue was due to incorrect use of step() statement which contained a jacoco() statement.

Incorrect usage....

step(
        jacoco(
                 execPattern: '**/build/jacoco/**.exec',
                 classPattern: '**/build/classes/java/main',
                 sourcePattern: '**/src',
                 inclusionPattern: 'com/testMgmt/**',
               )
    )

Correct usage (step() should not contain jacoco() )....

        jacoco(
                 execPattern: '**/build/jacoco/**.exec',
                 classPattern: '**/build/classes/java/main',
                 sourcePattern: '**/src',
                 inclusionPattern: 'com/testMgmt/**',
               )
  • Related