I need to fail jenkins job if any linux command return error message

2,189 views
Skip to first unread message

Praju

unread,
Nov 22, 2022, 7:41:17 AM11/22/22
to Jenkins Users
Hi ,
I need to fail jenkins job if any linux command return error message , could any one help one this

Thank you

Alex Earl

unread,
Nov 22, 2022, 7:47:08 AM11/22/22
to jenkins...@googlegroups.com
This is the default for Jenkins, if a command exits with a non-zero exit code, then the job should already fail. 

--
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/16344cad-dadf-4c55-a41f-a32acb3b82d9n%40googlegroups.com.


--

Dirk Heinrichs

unread,
Nov 22, 2022, 7:50:08 AM11/22/22
to jenkins...@googlegroups.com
Am Dienstag, dem 22.11.2022 um 03:47 -0800 schrieb Praju:

I need to fail jenkins job if any linux command return error message , could any one help one this

By default, Jenkins runs "Execute Shell" steps with "/bin/sh -e -x". Due to "-e", the step will fail if any of its commands fail. And if the step fails, the build fails, too.

HTH...

Dirk
-- 
Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenText ™ Discovery | Recommind
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Vertretungsberechtigte Geschäftsführer Gordon Davies, Madhu Ranganathan, Christian Waida, Registergericht Amtsgericht Bonn, Registernummer HRB 10646
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.

kakam...@gmail.com

unread,
Nov 22, 2022, 8:02:12 AM11/22/22
to \'Dirk Heinrichs\' via Jenkins Users
throw exception in groovy

---Original---
From: "'Dirk Heinrichs' via Jenkins Users"<jenkins...@googlegroups.com>
Date: Tue, Nov 22, 2022 20:49 PM
Subject: Re: I need to fail jenkins job if any linux command return error message
--
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.

Dirk Heinrichs

unread,
Nov 22, 2022, 8:08:10 AM11/22/22
to jenkins...@googlegroups.com
Am Dienstag, dem 22.11.2022 um 21:01 +0800 schrieb kakam...@gmail.com:

throw exception in groovy

The question is about Linux commands, not Groovy.

Bye...

Praju

unread,
Nov 22, 2022, 8:11:31 AM11/22/22
to Jenkins Users
Hi,
below is my configuration:

    echo "welcome"
    echo ${var}      ( Note : I am not defined var)
    echo "hello"

expected output status: failure

output:
         
             + echo welcome 
                welcome 
             + echo 

              + echo hello 
                 hello 
              Finished: SUCCESS 
image.png

Daniel Beck

unread,
Nov 22, 2022, 8:22:53 AM11/22/22
to jenkins...@googlegroups.com
On Tue, Nov 22, 2022 at 2:11 PM Praju <praju...@gmail.com> wrote:
Hi,
below is my configuration:

    echo "welcome"
    echo ${var}      ( Note : I am not defined var)
    echo "hello"

expected output status: failure

output:
         
             + echo welcome 
                welcome 
             + echo 

              + echo hello 
                 hello 
              Finished: SUCCESS 

`echo ${var}` didn't fail. As you can see, it printed an empty line. By default, bash allows references to undefined variables. Use `set -o nounset` to change this behavior.

This really isn't a Jenkins question, this is a question about shell use, and should be asked in the appropriate forum.


Dirk Heinrichs

unread,
Nov 22, 2022, 8:24:51 AM11/22/22
to jenkins...@googlegroups.com
Am Dienstag, dem 22.11.2022 um 05:11 -0800 schrieb Praju:

    echo ${var}      ( Note : I am not defined var)

echo NEVER fails. If ${var} is not defined, echo will output an empty string, so you'll see an empty new line in your build's log.

If you want it to fail, you'd need to test whether the variable is defined, maybe like so:

[ -n ${var} ] || exit 1

See "man test" for the details.

Bye...

Praju

unread,
Nov 22, 2022, 8:54:12 AM11/22/22
to Jenkins Users
Hi ,
The above one I am taking as example but actual configuration is:
                      < python_file> -D&1 2 | tee gen.file.log
above command   return "ValueError: No JSON object could be decoded"
but the job build status is showing success

Thanks

Daniel Beck

unread,
Nov 22, 2022, 8:58:29 AM11/22/22
to jenkins...@googlegroups.com
On Tue, Nov 22, 2022 at 2:54 PM Praju <praju...@gmail.com> wrote:
Hi ,
The above one I am taking as example but actual configuration is:
                      < python_file> -D&1 2 | tee gen.file.log
above command   return "ValueError: No JSON object could be decoded"
but the job build status is showing success

set -o pipefail.

You're still asking in the wrong forum.

Praju

unread,
Nov 22, 2022, 9:10:23 AM11/22/22
to Jenkins Users
Thank you all , it is working for me
Reply all
Reply to author
Forward
0 new messages