Skip to content
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 · 9 comments
Closed

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

grooverdan opened this issue Apr 27, 2015 · 9 comments
Labels

Comments

@grooverdan
Copy link

@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
Copy link
Member

@BanzaiMan 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
Copy link
Author

@grooverdan 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
Copy link
Member

@BanzaiMan 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
Copy link

@weitjong 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
Copy link
Author

@grooverdan 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
Copy link
Member

@BanzaiMan BanzaiMan commented May 4, 2015

Improvement to the documentation is also welcome!

l2fprod pushed 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
Copy link

@ryansmith94 ryansmith94 commented Feb 23, 2016

Thanks @weitjong 👍

@wiprodev
Copy link

@wiprodev 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.

tomszilagyi added a commit to tomszilagyi/banks2ledger that referenced this issue Apr 5, 2018
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
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
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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
@BanzaiMan @grooverdan @ryansmith94 @weitjong @wiprodev and others
You can’t perform that action at this time.