Travis reports a build success even though the npm publish failed?

Your script must have exited with an exit status of 0. How Travis is designed is that, heir-archly this is the only thing Travis cares about.

If you are running a script that does:

npm publish

Then it should do:

npm publish || exit 1

Or something similar in nature, to make sure that the script with that command exits with a non-zero status if the npm publish command fails. You didn’t include any example of your code but this is what I suspect may be happening here.

Actually it’s even more complicated that that. Let’s say that you have one script, and let’s say script1 is the one that fails:

#!/bin/sh

exit 1

And on the other hand you have another script, let’s call it script2 and that runs script1:

#!/bin/sh

./script1

Then running ./script2 (obviously) will also result in error when running:

./script2 && echo OK || echo ERROR

Yes, it will print ERROR, but when you have another command later:

./script1

echo

Then running ./script2 this time will not return the error this time via:

./script2 && echo OK || echo ERROR

That will end up printing: OK.

So if your npm publish command is the last command in your script then it should result in the entire script returning an error status to the system, but if it’s not then the system will get a status of 0 meaning success.

It all depends on how the script that Travis is running actually looks like. A short answer is that Travis CI does not check the exit status from the npm publish command, and this has been historically been the case.

1 Like