Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add multi-line bash EOD command to gitlab-ci.yml?

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: 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

How can I pass it in such way so that gitlab-runner execute this command in multi-line manner when passing it to bash?

like image 823
holms Avatar asked Jun 27 '18 12:06

holms


1 Answers

Found it finally

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
like image 56
holms Avatar answered Sep 17 '22 23:09

holms