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

Here’s the tail end of the log:

Deploying application
NPM API key format changed recently. If your deployment fails, check your API key in ~/.npmrc.
~/.npmrc size: 48
npm ERR! publish Failed PUT 403
npm ERR! Linux 4.8.12-040812-generic
npm ERR! argv "/home/travis/.nvm/v0.10.48/bin/node" "/home/travis/.nvm/v0.10.48/bin/npm" "publish"
npm ERR! node v0.10.48
npm ERR! npm  v2.15.1
npm ERR! code E403
npm ERR! "You cannot publish over the previously published version 1.1.5." : openssl-self-signed-certificate
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <>
npm ERR! Please include the following file with any support request:
npm ERR!     /home/travis/build/neverendingqs/openssl-self-signed-certificate/npm-debug.log
No stash found.
Done. Your build exited with 0.

In case it’s important, I have the test script in packages.json set to exit 0, but that occurs before the publish phase, so that shouldn’t be the problem(?).

Really confused, thank you…

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:


exit 1

And on the other hand you have another script, let’s call it script2 and that runs 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:



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