这个问题已被问过多次,但大多数问题都很容易解决,尽管使用工具expect
它没有像我预期的那样工作:
/usr/bin/expect <<EOD
spawn npm adduser
expect {
"Username:" {send "$USERNAME\r"; exp_continue}
"Password:" {send "$PASSWORD\r"; exp_continue}
"Email: (this IS public)" {send "$EMAIL\r"; exp_continue}
}
EOD
出于相同目的,还有更简单的变体:
npm adduser <<!
$NPM_USERNAME
$NPM_PASSWORD
$NPM_EMAIL
!
.gitlab-ci.yml:这样它会产生一行字符串,这不好并且命令将无法工作
npm_push:
dependencies:
- test
script:
- npm adduser <<!
$NPM_USERNAME
$NPM_PASSWORD
$NPM_EMAIL
!
- npm config set registry https://$NPM_URL
- npm push
如何以这种方式传递它,以便 gitlab-runner 在将其传递给 bash 时以多行方式执行此命令?
终于找到了
npm_publish:
stage: deploy
only:
- master
script:
- apk update
- apk add expect git alpine-sdk python python-dev
- npm config set registry https://$NPM_URL
- npm install publish
- |
/usr/bin/expect <<EOD
spawn npm adduser
expect {
"Username:" {send "$NPM_USERNAME\r"; exp_continue}
"Password:" {send "$NPM_PASSWORD\r"; exp_continue}
"Email: (this IS public)" {send "$NPM_EMAIL\r"; exp_continue}
}
EOD
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)