Reputation: 1234
How do I publish to npm using Travis CI? I've tried the following .travis.yml:
language: nodejs
node_js:
- '6'
- '6.1'
- '5.11'
before_script:
- npm install -g nodeunit
script: nodeunit
deploy:
provider: npm
email: my_email
api_key: "encrypted"
But when it comes to the npm bit , I get:
npm ERR! publish Failed PUT 400
npm ERR! Error: Not found : package-name
Any ideas?
UPDATE
With
api_key:
secure: "..."
I get another error:
NPM API key format changed recently. If your deployment fails, check your
API key in ~/.npmrc.
http://docs.travis-ci.com/user/deployment/npm/
~/.npmrc size: 53
env: <this is my unencrypted api key>: No such file or directory
SOLUTION
Finally solved it. The npm version on travis was really old (1.4.28). All I had to do was to put a :
before_script:
- npm install -g npm@'>=3'
And now it works!
Upvotes: 0
Views: 2220
Reputation: 12870
I see that you have solved, but I want share my working solution:
First I have generated a npm-token following these instruction.
Briefly I have done the login to npm with npm login
on my pc and then get it with cat ~/.npmrc
to get it.
Then I have added an enviroment var to travis:
Finally I have added to .travis.yml
:
deploy:
provider: npm
email: [email protected]
api_key: $NPM_TOKEN
on:
tags: true
Which will publish to npm repository only when the build is successfully and when any tag are added to the git repository (so you could publish only when you need it).
Upvotes: 0
Reputation: 7188
There are a few things that might be going wrong. First, have you checked your package.json
and made sure there is a name
property? Or does the name conflict with an existing npm package? The error message suggests that there is something wrong there.
But there is another problem. Your API key appears to be the string literal "encrypted"
, unless you are just using that as a placeholder for this example. It should look something like this:
provider: npm
email: [email protected]
api_key:
secure: "Esiel6Dws/vjwNshQ/nmx43+7/lpqsl8Dkd ..."
skip_cleanup: true
Also note the skip_cleanup
property. If you want to publish any artifacts of your build, you should include this.
The encryption can be done with the Travis CLI. See the encrypt
and setup
commands.
For a working example, see my .travis.yml
file on this project on GitHub.
Finally, make sure your API key is correct. On the computer on which you are logged in to npm, check your ~/.npmrc
file.
nano ~/.npmrc
Then find the line that starts with //registry.npmjs.org/:_authToken=
. Make sure that you use this token as your API key in .travis.yml
. The token will be valid for as long as you are logged in to npm on that computer.
Upvotes: 2