How to run Batch Scripts/Commands in Jenkinsfile

In this post we will be seeing how one can run Batch Scripts and commands in Jenkins using Jenkinsfile.

So let us see sample Jenkinsfile,

node {
    stage('Preparation') {
       //Preparation and checkout the code 
    }
    stage('Build') {
       //Build command     
    }
 }

So this is sample Scripted Pipeline which is doing checkout and building the code.

Now let’s us say we need to do some parsing or post build step using batch commands.

We can introduce one more stage named Post build action and pass batch commands as shown below.

node {
    stage('Preparation') {
       //Preparations and checkout the code 
    }
    stage('Build') {
       //Build command     
    }
    stage('Post build action'){
    bat '''  ECHO Hello World  '''
    }
 }

So you can pass all your batch commands inside the triple quotes.

Leave a comment