gpt4 book ai didi

bash - 如何将多行 bash EOD 命令添加到 gitlab-ci.yml?

转载 作者:行者123 更新时间:2023-11-29 09:21:04 42 4
gpt4 key购买 nike

这个问题被问了很多次,但大多数都很容易解决,尽管使用工具 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

关于bash - 如何将多行 bash EOD 命令添加到 gitlab-ci.yml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51062370/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com