It doesn't recognize shell script syntax


(Kushan Jayathilake) #1

Hi,

I have a shell script and I have configured with Jenkins through “add post build action” plugin.
There I have selected “Execute shell” option and given the absolute path to the script file.

When the build is running it throws it below errors. Note that Jenkins is running on Windows.
When I run the same script in Command Prompt it runs without an issue.

C:\Software\Jenkins\workspace\SFDC>#!/bin/bash
'#!' is not recognized as an internal or external command,
operable program or batch file.

C:\Software\Jenkins\workspace\SFDC># Constants 
'#' is not recognized as an internal or external command,
operable program or batch file.

C:\Software\Jenkins\workspace\SFDC>readonly devhuburl="https://login.salesforce.com" 
'readonly' is not recognized as an internal or external command,
operable program or batch file.

(Lisa Mathew) #2

Hi @Kushan_Jayathilake,

looks like you are trying to execute linux command in windows machine. It will not work. You should execute the bash script on a linux slave


(Kushan Jayathilake) #3

Hi Lisa,

Thanks for your reply. But the shell script executes successfully in Windows Command Prompt. I hope there should be another way to run it in Jenkins also, may be we can ask Jenkins to run the shell script in Command Prompt?


(Rohit Kumar Singh) #4

Hi @Kushan_Jayathilake,

Windows will not support shell scripts out of the box as per my knowledge. You can install Cygwin or Git for Windows, go to Manage Jenkins > Configure System Shell and point it to the location of sh.exe file found in their installation.

For example:
C:\Program Files\Git\bin\sh.exe

There is another option I’ve discovered. This one is better because it allowed me to use shell in pipeline scripts with simple sh “something”.

Add the folder to system PATH. Right click on Computer, click properties > advanced system settings > environmental variables, add C:\Program Files\Git\bin\ to your system Path property.


(Rohit Kumar Singh) #5

Hi @Kushan_Jayathilake,

Windows will not support shell scripts out of the box as per my knowledge. You can install Cygwin or Git for Windows, go to Manage Jenkins > Configure System Shell and point it to the location of sh.exe file found in their installation. For example:

C:\Program Files\Git\bin\sh.exe
There is another option I’ve discovered. This one is better because it allowed me to use shell in pipeline scripts with simple sh “something”.

Add the folder to system PATH. Right click on Computer, click properties > advanced system settings > environmental variables, add C:\Program Files\Git\bin\ to your system Path property.

Thanks,


(Kushan Jayathilake) #6

Hi @Lisa,

But I can execute the same shell script successfully in Windows Command Prompt. It only the Jenkins fails to execute it. Is there any configuration to be made in order to execute Shell Scripts?