LoginSignup
43
20

More than 3 years have passed since last update.

[GitHub Actions] bash のオプション(-xe)を指定する

Last updated at Posted at 2020-02-01

Tl;Dr

shellキーワードにてbash -xe {0}と指定できる。

jobs:
  build:
...
    steps:
    - name: Hello
      shell: bash -xe {0} # custom shell
      run: |
        echo "Hello!"

なぜ利用したい?

GitHub Actionsでシェルを実行する時、デフォルトでは-xオプションが指定されていないため、エラーが発生したときにどこで失敗したのか分かりづらいことがある。

以下では2行目でechoo "Bad"とタイポしているが、それが原因で失敗していることが分かりづらい。
image.png

shellキーワードでbash -xe {0}を指定しておけば、以下のように失敗した箇所が分かりやすい。
image.png

また、デフォルトでは-eオプションが指定されているため、いずれかのコマンドが失敗したタイミングで終了扱いになるが、その挙動が好ましくない場合bash -x {0}と指定することで回避できる。

Custom shell

公式ドキュメントに記載がある。

You can set the shell value to a template string using command […options] {0} [..more_options]. GitHub interprets the first whitespace-delimited word of the string as the command, and inserts the file name for the temporary script at {0}.

command […options] {0} [..more_options]という書式で指定すればよいと書かれており、今回はbash -xe {0}と指定した(more_optionsは指定していない)が、他にも任意のコマンドを指定することができる。

終わりに

ググってすぐに見つからなかったので、比較的ググラビリティの高そうなタイトルで簡単に書いてみた。

43
20
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
43
20