2

I have to build a jenkins pipeline job using groovy script, what the job has to do is, first run an windows batch command, and only if the batch command build is successful, it should call build for another job. How can I find out is the windows batch command was build successfully. I am showing sample code for the query.

  import groovy.json.JsonSlurper;
  import hudson.model.*
  import hudson.EnvVars
  pipeline {
    agent any 
    stages {
    stage('Build')
    {
     steps{
    bat 'some batch command here'
   // if(bat build successful)---> need help here
    build 'xyz' //xyz is another job that I am calling here
   }
}

}
NeN
  • 23
  • 4

1 Answers1

1

This is the default behavior of steps: if one of the step fails, it stops.

That bat step includes:

Normally, a script which exits with a nonzero status code will cause the step to fail with an exception

If your batch command does fail, its errorlevel should be different of 0, which is enough to make the steps chain fail.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250