3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitlab-ciのscriptでfor文を使うとエラーになる時の対応方法

Posted at

gitlab-ciのscriptでfor文を使うとエラーになる時の対応方法

はじめに

gitlab-ciのscriptで何の変哲もないfor文を書いたつもりが、エラーになってくっそハマったので、
同じ状況になっている人を救うためにも公開します。

環境

Amazon Linux 2


# gitlab-runner -v
Version:      11.6.0
Git revision: f100a208
Git branch:   11-6-stable
GO version:   go1.8.7
Built:        2018-12-22T11:56:10+0000
OS/Arch:      linux/amd64

問題となったスクリプト

一見、何も問題が内容に見える scripttest.shみたいな感じでshファイルにしたら問題なく動く。

gitlab-ci.yml

variables:
  TARGET: "apple banana cherry"

test:
  stage: test
  script:
    - for target in ${TARGET} ; 
    - do
    - echo $target
    - done
  tags:
    - test
  only:
    - master

エラー内容

しかし、scriptを実行すると以下のエラーが発生

bash: eval: line 111: syntax error near unexpected token `echo'
ERROR: Job failed: exit status 2

対応方法

doを改行しないで書くと問題なく動く

gitlab-ci.yml

variables:
  TARGET: "apple banana cherry"

test:
  stage: test
  script:
    - for target in ${TARGET} ; do # ←doを改行しない
    - echo $target
    - done
  tags:
    - test
  only:
    - master

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?