Execute Batch Script not working in Jenkins Pipeline Job Execute Batch Script not working in Jenkins Pipeline Job powershell powershell

Execute Batch Script not working in Jenkins Pipeline Job


Interesting. Your problem doesn't seem to be in your script because you already explained that it works in a batch job.

I don't know how your pipeline is written, but I would suggest taking a look to Stage, Lock and Milestone which is probably what you need.

The stage step is a primary building block in Pipeline, dividing the steps of a Pipeline into explicit units and helping to visualize the progress using the "Stage View" plugin

I guess you could add a stage block like this one in your pipeline:

 stage("Previous Step") {      // Some previous step    }stage("Wait for Script Execution") {  // Call your script  bat 'powershell.exe -ExecutionPolicy Bypass  "D:\\Test\\Deploymentscripts\\PowerShellScript\\FileTransfer.ps1 $env:EndMarket $env:Environment"'} stage("Next Step") {      // Script already finished its execution    }

But without your pipeline info is just a guessing. Also to improve your script compatibility avoiding "bat and ExcutionPolicy" and using the PowerShell plugin, with that plugin you could simplify your code like this:

powershell -File your_script.ps1

EDIT: I forgot to mention that you can try a different alternative to powershell and the winscp lib using "scp" direct compatibility between Windows and Linux, I'm talking about Cygwin.

With Cygwin installed (with scp) you can use scp as it was a Linux box and a bash script instead powershell:

D:/cygwin-64/bin/run.exe /usr/bin/bash -lic \"/home/user/file.sh\" 

In this case I'm running a script silently through Cygwin within a Jenkins Project with a "Run Windows Batch" option. In the script you can add shell commands and the scp instructions you want.

It may seems a little bit more complex but adds more flexibility to perform Windows - Linux tasks.

I've detailed more examples in my blog, you may find it useful.

As avvi mentioned you should check if that variables are being loaded.


You are not calling the script correctly. You are passing in $Env in the powershell invocation which is a powershell variable.

You are in batch mode so should be passing in %.

bat 'powershell.exe -ExecutionPolicy Bypass  "D:\\Test\\Deploymentscripts\\PowerShellScript\\FileTransfer.ps1" "%EndMarket%" "%Environment%"'