Space Automation: stop job when some command inside shellScript return exit code different to 0

Hi, I need to stop the job execution when Rubocop rules fail. I configured rubocop to throw an error when it finds any offenses and I checked that the exit code is 1 when there are any offense, but during the job execution, it ignores the process exit code and keep going to next command though failOn block has nonZeroExitCode enable true.

 

job("Development Deploy") {
startOn {
gitPush {
branchFilter {
+"refs/heads/development"
}
}
}

failOn{
nonZeroExitCode { enabled = true}
}

container(displayName = "Deploy", image = "ruby:2.7.3") {
env.set("RAILS_ENV", "development")
env["PUBLIC"] = Secrets("public_key")
env["PRIVATE"] = Secrets("private_key")

shellScript {
interpreter = "/bin/sh"
content = """
echo Installing dependencies
gem install bundler
gem install rails
bundle install
echo Excuting Rubocop
bundle exec rubocop

......OTHER COMMANDS



""".trimIndent()
}
}
}

So I need to find a way stop the job execution when at least one command inside shell script fails I'll appreciate any help you can give me  

0
5 comments

Hi Oscar, may I ask if you considered using `set -e` command which allows exiting shell immediately if any of executed commands exits with a non-zero status? Thanks!

0

Hi Pavel, it worked like a charm. Thank you so much! 

0

Question, but how can I use the `set -e` command in a shellscript?

0

Christian Knauf, here's an example:

job("Example shell script") {
    container(displayName = "Say Hello", image = "ubuntu") {
        shellScript {
            content = """
                set -e
                echo Hello
                echo World!
            """
        }
    }
}
0

Please sign in to leave a comment.