1

The trouble I am facing is:

Say, I have a JAVA code and I intentionally put a syntax error there, then the compilation should make the build fail.

Similarly, if there's no error, the compilation should mark the build as success.

BUT the catch is, I don't want to run the code. I just want this Failure and Success based on compilation

I have written a TestNg code for an automated test and I am using this maven goal in Jenkins: clean compile test

This starts running the whole test and then brings the error on whichever line it's caught.

But I want to get this error during the compilation without running the test code.

1 Answers1

0

You can try catching the error and killing the maven process from the jenkins pipeline:

pipeline {
    agent any

    stages {
        stage('Compile') {
            steps {
                sh 'mvn compile'
            }
            post {
                failure {
                    script {
                        currentBuild.result = 'FAILURE'
                        sh 'pkill -f "mvn compile"'
                    }
                }
            }
        }
        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }
    }
}
seenukarthi
  • 8,241
  • 10
  • 47
  • 68
TudorIftimie
  • 1,050
  • 11
  • 21