Kworks Kworks - 1 month ago 21
Bash Question

How can I execute Shell script in Jenkins?

I am keeping the file a shell script

urltest.sh
file in
/var/lib/jenkins
and executing the file from jenkins build.

When I execute the build, It fails.

The Environment Variables are -
HOME - /var/lib/jenkins ;
JENKINS_HOME - /var/lib/jenkins


The console output comes as :

Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/AutoScript
[AutoScript] $ /bin/sh -xe /tmp/hudson2777728063740604479.sh
+ sh urltest.sh
sh: 0: Can't open urltest.sh
Build step 'Execute shell' marked build as failure
Finished: FAILURE


I am confused where I should keep the file so that it is executed.

Answer

If you see your error message it says

Building in workspace /var/lib/jenkins/workspace/AutoScript

and as per your comments you have put urltest.sh in

/var/lib/jenkins

hence jenkins is not able to find the file. In your build step do this thing, it will work

cd --which will point to /var/lib/jenkins

./urltest.sh --it will run your script

If it still fails try to chown the file as jenkin user may not have file permission, but I think if you do above step you will be able to run.