Kworks Kworks - 2 months ago 41
Bash Question

How can I execute Shell script in Jenkins?

I am keeping the file a shell script
file in
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/
+ sh
sh: 0: Can't open
Build step 'Execute shell' marked build as failure
Finished: FAILURE

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


If you see your error message it says

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

and as per your comments you have put in


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

./ --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.