New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

travis-build: preserving the status in $? #3771

Closed
grooverdan opened this Issue Apr 27, 2015 · 8 comments

Comments

Projects
None yet
5 participants
@grooverdan

grooverdan commented Apr 27, 2015

Whether make succeeds or fails $? is always 1.

script:
  - make -j 4
  - COMPILE_RESULT=$?
  - echo COMPILE_RESULT=${COMPILE_RESULT}

output:

..
The command "make -j 4" exited with 0.

$ COMPILE_RESULT=$?
The command "COMPILE_RESULT=$?" exited with 0.

$ echo COMPILE_RESULT=${COMPILE_RESULT}
COMPILE_RESULT=1
@BanzaiMan

This comment has been minimized.

Show comment
Hide comment
@BanzaiMan

BanzaiMan Apr 27, 2015

Member

Each line in the script section is processed by the travis_cmd bash function. (The value 1 comes from the immediately preceding test [[ -n "$retry" ]] on line 38.)

I understand the motivation for using $? this way (and potentially other special variables) in the script section, but achieving it without breaking the currently working builds may be hard.

I tend to think it is better to document this behavior, and advise writing a custom script if the user wants to do something involving $? in the script section.

Member

BanzaiMan commented Apr 27, 2015

Each line in the script section is processed by the travis_cmd bash function. (The value 1 comes from the immediately preceding test [[ -n "$retry" ]] on line 38.)

I understand the motivation for using $? this way (and potentially other special variables) in the script section, but achieving it without breaking the currently working builds may be hard.

I tend to think it is better to document this behavior, and advise writing a custom script if the user wants to do something involving $? in the script section.

@grooverdan

This comment has been minimized.

Show comment
Hide comment
@grooverdan

grooverdan Apr 27, 2015

I think anyone who's tried to use $? has come across this limitation and avoided it by writing a custom script (like I should be doing now). Thanks for the prompt response.

grooverdan commented Apr 27, 2015

I think anyone who's tried to use $? has come across this limitation and avoided it by writing a custom script (like I should be doing now). Thanks for the prompt response.

BanzaiMan added a commit to travis-ci/docs-travis-ci-com that referenced this issue Apr 27, 2015

@BanzaiMan

This comment has been minimized.

Show comment
Hide comment
@BanzaiMan

BanzaiMan Apr 27, 2015

Member

I've noted this in http://docs.travis-ci.com/user/customizing-the-build/#Note-on-%24%3F. (Improvement suggestions welcome!)

I'm closing this now.

Member

BanzaiMan commented Apr 27, 2015

I've noted this in http://docs.travis-ci.com/user/customizing-the-build/#Note-on-%24%3F. (Improvement suggestions welcome!)

I'm closing this now.

@BanzaiMan BanzaiMan closed this Apr 27, 2015

@weitjong

This comment has been minimized.

Show comment
Hide comment
@weitjong

weitjong Apr 27, 2015

The trick is, you have to get it right after the command.

make -j4; export COMPILE_RESULT=$?

Though in my .travis.yml I usually just combine the command using "&&" or "||" bash operator or inside another if statement, so I don't really need to use $? explicitly to get the exit status of the earlier command. e.g.:

make -j4 && other-cmd-to-execute-when-make-was-successful

or

make -j4 || other-cmd-to-execute-when-make-was-failed

weitjong commented Apr 27, 2015

The trick is, you have to get it right after the command.

make -j4; export COMPILE_RESULT=$?

Though in my .travis.yml I usually just combine the command using "&&" or "||" bash operator or inside another if statement, so I don't really need to use $? explicitly to get the exit status of the earlier command. e.g.:

make -j4 && other-cmd-to-execute-when-make-was-successful

or

make -j4 || other-cmd-to-execute-when-make-was-failed
@grooverdan

This comment has been minimized.

Show comment
Hide comment
@grooverdan

grooverdan Apr 29, 2015

@BanzaiMan , while I'm still not convinced that there is a person using $? to extract the value of [[ -n "$retry" ]] the alternative for documentation is here:

- COMPILE_RESULT=0 ; make -j4 || COMPILE_RESULT=$?; expr $COMPILE_RESULT != 0
- [ $COMPILE_RESULT -ge 2 ] && echo makefile error

So the two objectives in deciding this structure where to make $COMPILE_RESULT have the value of the return and to give travis a true/false indicator of the result of the compile. @weitjong suggestions are of course valid (though export is excessive) however sometime additional flexibility is needed.

grooverdan commented Apr 29, 2015

@BanzaiMan , while I'm still not convinced that there is a person using $? to extract the value of [[ -n "$retry" ]] the alternative for documentation is here:

- COMPILE_RESULT=0 ; make -j4 || COMPILE_RESULT=$?; expr $COMPILE_RESULT != 0
- [ $COMPILE_RESULT -ge 2 ] && echo makefile error

So the two objectives in deciding this structure where to make $COMPILE_RESULT have the value of the return and to give travis a true/false indicator of the result of the compile. @weitjong suggestions are of course valid (though export is excessive) however sometime additional flexibility is needed.

@BanzaiMan

This comment has been minimized.

Show comment
Hide comment
@BanzaiMan

BanzaiMan May 4, 2015

Member

Improvement to the documentation is also welcome!

Member

BanzaiMan commented May 4, 2015

Improvement to the documentation is also welcome!

l2fprod added a commit to IBM-Cloud/insights-search that referenced this issue Oct 7, 2015

ryansmith94 added a commit to LearningLocker/learninglocker that referenced this issue Feb 23, 2016

@ryansmith94

This comment has been minimized.

Show comment
Hide comment
@ryansmith94

ryansmith94 commented Feb 23, 2016

Thanks @weitjong 👍

@wiprodev

This comment has been minimized.

Show comment
Hide comment
@wiprodev

wiprodev Feb 27, 2016

Does Travis capture the non zero exit code for init scripts like sudo service xyz start ? In my case though the service fails to start it shows build successful.

wiprodev commented Feb 27, 2016

Does Travis capture the non zero exit code for init scripts like sudo service xyz start ? In my case though the service fails to start it shows build successful.

@d6y d6y referenced this issue Jun 23, 2017

Merged

Add travis-ci build #145

@chrissimpkins chrissimpkins referenced this issue Aug 28, 2017

Closed

Display config.log after build failures #1

2 of 2 tasks complete

tomszilagyi added a commit to tomszilagyi/banks2ledger that referenced this issue Apr 5, 2018

Fix test script error reporting on travis-ci
The travis-ci build was not marked as failed even though the test
script detected an error. The problem was the (otherwise normal) usage
of the $? bash variable, that conflicts with the way travis-ci runs
the script.

See: travis-ci/travis-ci#3771

ebellani added a commit to ebellani/banks2ledger that referenced this issue Apr 8, 2018

Fix test script error reporting on travis-ci
The travis-ci build was not marked as failed even though the test
script detected an error. The problem was the (otherwise normal) usage
of the $? bash variable, that conflicts with the way travis-ci runs
the script.

See: travis-ci/travis-ci#3771

bhagemeier added a commit to helmholtz-analytics/heat that referenced this issue Jun 21, 2018

Fix for Travis environment restrictions
I ran into travis-ci/travis-ci#3771. Use of $? is
dicouraged in .travis.yml, therefore building PyTorch has been externalized to a
script. Not sure whether travis_wait works within the script or needs to be
pulled back up to .travis.yml.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment