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.



Categories: Jenkins

Tags: , , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: