How to return an error code in bash if a condition is not true?

Asked

Viewed 10 times

0

I’m using the Travis-ci for an ongoing integration process, however, I’m having difficulty performing a specific validation after installing some components (apache, php...).

I currently have the following check (this is the validation test):

STRING=$(curl -Is --head "$URL_CURL_CHECK" | grep -o "HTTP/1.1 200 OK")
function check {
    if [[ $STRING == "HTTP/1.1 200 OK" ]]; then
        echo "sucesso"
    else
        echo "error"
    fi
}

URL_CURL_CHECK receives the URL to be verified. I would like to be able to make an exception in Travis-ci if the condition of this if was not successful, or better, code Return 0. Any idea how I do this?

  • 1

    I never messed with Travis... but he understands the exit code? If yes, you could add 'Exit 0' in the success condition and 'Exit 2' in the error condition. That is, your script will end as ERROR if you go to Exit 2. Then just Travis understand this output.

  • @Diego, done. It looks like it worked well.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.