How can i execute shell scripts from Jenkins ?

15,281 views
Skip to first unread message

Kendiol

unread,
Sep 27, 2011, 1:00:49 PM9/27/11
to Jenkins Users
Hello everyone,

I'm a complete newbie to Jenkins.
I'm trying to get Jenkins to monitor the execution of my shell script
so i that i don't have to launch them manually each time but i can't
figure out how to do it.
I found out about the "monitor external job" option but i can't
configure it correctly.
I know that Jenkins can understand Shell script exit code so this is
what i did :

test1(){
ls /home/user1 | grep $2
case $? in
0) msg_error 0 "Okay."
;;
*) msg_error 2 "Error."
;;
esac
}


It's a simplified version of my functions.
I execute them manually but i want to launch them from Jenkins with
arguments and get the results of course.
Can this be done ?

Thanks.

Derek Brown

unread,
Sep 27, 2011, 4:19:58 PM9/27/11
to Jenkins Users
Create a Jenkins job, ( i created a free-style software project)
In the configuration of that job there is a "Build" section with "Add
build step" pulldown.
Add a "Execute Shell" step, and insert your code.

Hope this helps!
Derek . . .

Vincent Hardion

unread,
Sep 28, 2011, 1:36:40 AM9/28/11
to jenkins...@googlegroups.com
Hi,

Also you can define parametrized build.
These parameters will appear as env var.
More explanation here : https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build

Best regards,

Vincent

Kendiol

unread,
Sep 29, 2011, 4:16:30 AM9/29/11
to Jenkins Users
Thanks guys, so to execute my script I simply put ./myscript as the
command of the FreeStyle Build and i set the pamaeters to call my
functions.


On 28 sep, 07:36, Vincent Hardion <vincent.hard...@synchrotron-
> >> Thanks.- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Braj Mohan

unread,
Mar 18, 2020, 11:09:32 AM3/18/20
to Jenkins Users
Hi Derek Brown,

Can i directly call my .sh file into build section.

Thanks

Siddhesh Malpani

unread,
Mar 18, 2020, 12:25:34 PM3/18/20
to Jenkins Users
Mohan,

Yes of course you can do that. Simply ad the shell script file name in the 'Execute Shell' step as explained by Derek. Remember that you've give the path of your file relative to your workspace directory. Suppose your worskapce dir is 'build-dev' and the shell script 'patch.sh' is located in a dir 'scripts' under the workspace. Then you'll have to give it's path as:

./scripts/patch.sh

And you're good to go.

Cheers,
Siddhesh

Gil Jensen

unread,
Mar 5, 2021, 12:12:02 PM3/5/21
to Jenkins Users
can you tell me why Jenkins would get a different result from the  shell scripts  alone?

Eric Pyle

unread,
Mar 5, 2021, 2:47:21 PM3/5/21
to jenkins...@googlegroups.com
Typically such problems are because the shell script is tested under a different user account than the one used by Jenkins. This may result in commands not being found due to different $PATH settings or permission errors because of different user permissions. It's hard to be more specific without knowing more about the errors you are seeing.

Eric
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c6d9f1a7-ac7a-4e88-9267-ee8ec1386223n%40googlegroups.com.

Jensen, Gil

unread,
Mar 5, 2021, 3:15:46 PM3/5/21
to jenkins...@googlegroups.com, Eric Pyle

Thanks Eric

 

Thanks and Regards

Gil Jensen

General Dynamics Land Systems

M:616-610-0914

D:586-825-5421

jen...@gdls.com

 

From: jenkins...@googlegroups.com [mailto:jenkins...@googlegroups.com] On Behalf Of Eric Pyle
Sent: Friday, March 5, 2021 2:47 PM
To: jenkins...@googlegroups.com
Subject: Re: How can i execute shell scripts from Jenkins ?

 


CAUTION EXTERNAL EMAIL

THIS EMAIL WAS SENT FROM OUTSIDE GDLS. PLEASE DO NOT OPEN ANY URL LINKS, OPEN ATTACHMENTS OR REPLY TO THIS EMAIL IF YOU ARE UNABLE TO VERIFY THE SENDER’S EMAIL ADDRESS

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.


This is an e-mail from General Dynamics Land Systems. It is for the intended recipient only and may contain confidential and privileged information. No one else may read, print, store, copy, forward or act in reliance on it or its attachments. If you are not the intended recipient, please return this message to the sender and delete the message and any attachments from your computer. Your cooperation is appreciated.

Jensen, Gil

unread,
Mar 5, 2021, 3:15:46 PM3/5/21
to jenkins...@googlegroups.com

Thank you, I have done this but they are still not running equally

 

Thanks and Regards

General Dynamics Land Systems

Gil Jensen

From: jenkins...@googlegroups.com [mailto:jenkins...@googlegroups.com] On Behalf Of Gil Jensen
Sent: Friday, March 5, 2021 12:04 PM
To: Jenkins Users <jenkins...@googlegroups.com>
Subject: Re: How can i execute shell scripts from Jenkins ?

 


CAUTION EXTERNAL EMAIL

THIS EMAIL WAS SENT FROM OUTSIDE GDLS. PLEASE DO NOT OPEN ANY URL LINKS, OPEN ATTACHMENTS OR REPLY TO THIS EMAIL IF YOU ARE UNABLE TO VERIFY THE SENDER’S EMAIL ADDRESS

can you tell me why Jenkins would get a different result from the  shell scripts  alone?

--

You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c6d9f1a7-ac7a-4e88-9267-ee8ec1386223n%40googlegroups.com [groups.google.com].

Reply all
Reply to author
Forward
0 new messages