如何在gitlab-ci.yml中添加多行bash EOD命令? [英] How can I add multi-line bash EOD command to gitlab-ci.yml?
本文介绍了如何在gitlab-ci.yml中添加多行bash EOD命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题被问了很多遍,但是大多数问题很容易解决,尽管使用工具expect
不能按我预期的那样工作:
This question been asked multiple times but most of them was easy to solve, although using tool expect
it doesn't work as I've expected:
/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
出于相同的目的,还有一个更简单的变体:
There's also more simple variant for the same purpose:
npm adduser <<!
$NPM_USERNAME
$NPM_PASSWORD
$NPM_EMAIL
!
.gitlab-ci.yml:这样将产生一个不好的行字符串,命令将不起作用
.gitlab-ci.yml: this way it will produce one line string which is not good and command won't work
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时以多行方式执行此命令?
How can I pass it in such way so that gitlab-runner execute this command in multi-line manner when passing it to 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
这篇关于如何在gitlab-ci.yml中添加多行bash EOD命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文