diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-11-27 05:05:04 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-11-27 06:07:46 +0900 |
| commit | c754d24b162ecd504f3c4bdd8632045dd0398768 (patch) | |
| tree | 362323710bb329ad609d379df4e4a429e4229fd2 /services/nuldoc/content/posts/2024-04-21 | |
| parent | d1014de68415df8f0a5dc3389332e086119c6198 (diff) | |
| download | nsfisis.dev-c754d24b162ecd504f3c4bdd8632045dd0398768.tar.gz nsfisis.dev-c754d24b162ecd504f3c4bdd8632045dd0398768.tar.zst nsfisis.dev-c754d24b162ecd504f3c4bdd8632045dd0398768.zip | |
feat(nuldoc): Djot to Markdown
Diffstat (limited to 'services/nuldoc/content/posts/2024-04-21')
| -rw-r--r-- | services/nuldoc/content/posts/2024-04-21/pipefail-option-in-gitlab-ci-cd.md (renamed from services/nuldoc/content/posts/2024-04-21/pipefail-option-in-gitlab-ci-cd.dj) | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/services/nuldoc/content/posts/2024-04-21/pipefail-option-in-gitlab-ci-cd.dj b/services/nuldoc/content/posts/2024-04-21/pipefail-option-in-gitlab-ci-cd.md index 9872d28..41b9513 100644 --- a/services/nuldoc/content/posts/2024-04-21/pipefail-option-in-gitlab-ci-cd.dj +++ b/services/nuldoc/content/posts/2024-04-21/pipefail-option-in-gitlab-ci-cd.md @@ -17,17 +17,15 @@ isInternal = true date = "2024-04-21" remark = "ブログ記事として一般公開" --- -::: note +:::note この記事は、2022-11-17 に [デジタルサーカス株式会社](https://www.dgcircus.com/) の社内 Qiita Team に公開された記事をベースに、加筆修正して一般公開したものです。 ::: ハマったのでメモ。 -{#background} -# 前提 +# 前提 {#background} -{#gitlab-ci-cd} -## GitLab CI/CD について +## GitLab CI/CD について {#gitlab-ci-cd} GitLab CI/CD では、Docker executor を用いて任意の Docker image 上でスクリプトを走らせることができる。 @@ -61,8 +59,7 @@ hello-world: 失敗するコマンドをパイプに接続した。通常 Bash では、パイプの最後のコマンドの exit code が全体の exit code になる。 -{#pipefail-option} -## `pipefail` オプションについて +## `pipefail` オプションについて {#pipefail-option} 前述したようなケースにおいて、途中で失敗したときに全体を失敗させるには、`pipefail` オプションを有効にする。 @@ -76,8 +73,7 @@ set +o pipefail こうすると、パイプ全体が失敗するようになる。 この設定は、デフォルトだと off になっている。 -{#problem} -# 発生した問題 +# 発生した問題 {#problem} 次のような GitLab CI/CD ジョブが失敗してしまった。 @@ -119,8 +115,7 @@ set +o pipefail なぜスクリプト内で `set -o pipefail` しているわけでもないのに `pipefail` が on になっているのか。 -{#where-pipefail-is-enabled} -# どこで `pipefail` が on になるか +# どこで `pipefail` が on になるか {#where-pipefail-is-enabled} `.gitlab-ci.yml` で明示的には書いていないので、GitLab Runner (GitLab CI/CD のスクリプトを実行するプログラム) が勝手に追加しているに違いない。 そう仮説を立てて [GitLab Runner のリポジトリ](https://gitlab.com/gitlab-org/gitlab-runner) を調査したところ、 [ソースコード中の以下の箇所](https://gitlab.com/gitlab-org/gitlab-runner/-/blob/c75da0796a0e3048991dccfdf2784e3d931beda4/shells/bash.go#L276) で `set -o pipefail` していることが判明した (コメントは筆者による)。 @@ -131,8 +126,7 @@ set +o pipefail buf.WriteString("if set -o | grep pipefail > /dev/null; then set -o pipefail; fi; set -o errexit\n") ``` -{#how-to-solve} -# どのように解決するか +# どのように解決するか {#how-to-solve} 通常の Bash スクリプトを書く場合と同様に、`pipefail` が on になっていては困る場所だけ off にしてやればよい。 @@ -149,7 +143,6 @@ buf.WriteString("if set -o | grep pipefail > /dev/null; then set -o pipefail; fi when: always ``` -{#remarks} -# 備考 +# 備考 {#remarks} なお、上述した実装ファイルは `shells/bash.go` だが、`alpine:latest` の例でもそうであったように、シェルが `sh` である場合にも適用される。 |
