I want to automate the npm login process via a bash script.
I tried it with this snippet:
/usr/bin/expect -f - <<EOD
spawn npm adduser
expect "Username:"
send "myUserName\n"
expect "mail: (this IS public)"
send "my@email.com\n"
EOD
But without luck.
Note: I will change the strings with env variables
I had this issue but the only way of getting round it was to wrap expect into a docker image. You can use it like so:
https://github.com/bravissimolabs/docker-generate-npm-authtoken
@Aurélien Thieriot: thanks for the hint.
i have two solutions for my problem:
solution 1:
create/override
~/.npmrc
by following shell script:solution 2:
i know the order of the questions. so i can do the following:
Note: solution 2 works only when the user isn't added yet
Otherwise the
$NPM_PASSWORD
is not necessaryI found that on Windows Server 2012R2, there is some odd behaviour with service accounts. This method worked for me (as part of a Jenkins build, under bash):
My Solution is to use plugin npm-login-cmd
login work on enterprice npm repository
This way works and with a more elegant expect:
I don't know if it is in any way secured so please do some research before.
But the fact is that
npm
is storing all those informations into a file. If you look at:It could be interesting enough so you could do the login dance only once.