Selvaraj M A
Selvaraj M A

Reputation: 3136

Executing custom shell script to build in jenkins

I have setup a jenkins job to build my project. I have a jake.sh file in my project and the code is pulled from github. I want "npm install" command to be executed and then jake.sh to be executed once the the code is checked out.

How can I configure this in jenkins? I have tried givin ./jake.sh and jake.sh in Build->Execute Shell section

Upvotes: 3

Views: 22315

Answers (2)

jakub.g
jakub.g

Reputation: 41268

A workaround for shell scripts can be to run the script as

bash ./jake.sh 

instead of

./jake.sh

Then you don't have to do chmod. Useful when you wipe the workspace before every build.

In the same manner, if you have a nodejs shell script or python script, you can run node myscript.js / python myscript.py.

Upvotes: 3

Nicolás Arias
Nicolás Arias

Reputation: 1073

According what you tell I think the problem can be

  • The script is not marked as a executable. In this case add in Build -> Execute Shell (in case you have linux) sudo chmod 777 path_to_script/jake.sh.
  • The script is not in the base directory. Remembeber that when you execute a bash script, the current directory is /path_to_job/workspace. So you have first to move to the script folder (cd path_to_script) or specify the path when running it: ./path_to_script/jake.sh.

I hope this solves your problem.

Upvotes: 6

Related Questions