2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitLab CIのtriggerを使って別のパイプラインを起動してみる

2
Last updated at Posted at 2026-12-01

はじめに

GitLab CIにはパイプラインから別のパイプラインを起動できるtriggerという仕組みが用意されている。

今回はtriggerを使った場合、どのように動くのか確認します。

triggerとは

通常、pushやマージリクエストを起点にパイプラインが実行されるが、triggerを使えばパイプラインから別のパイプラインを動かすことができる。

このtriggerには大きく分けて2種類があります。

  • multi-project-pipelines:別プロジェクトのパイプラインを起動
  • parent-child-pipelines:同じプロジェクトで子パイプラインを起動

今回はparent-child-pipelinesを使います。

子パイプラインを起動してみる

次の2つのファイルを用意する。

.gitlab-ci.yml
stages:
  - test

trigger-test:
  stage: test
  trigger:
    include:
      - local: child.yml
child.yml
stages:
  - test

test:
  stage: test
  script:
    - echo "Child pipeline started"

この状態でパイプラインを起動すると、trigger-testジョブから子パイプラインが起動する。

子パイプラインが失敗した場合の動き

子パイプラインが失敗すると、親パイプラインがどのように動くのか確認するために先程のchild.ymlを意図的に失敗させてみます。

child.yml
stages:
  - test

test:
  stage: test
  script:
    - echo "Child pipeline started"
+   - exit 1

この状態でパイプラインを動かすと子パイプラインは失敗していますが、親パイプラインは成功しています。

つまり、親パイプラインは子パイプラインを実行した時点で処理は成功とみなし、子パイプラインの結果は見ないようです。

では、子パイプラインの結果を待ちたいケースはどうしたらいいのか?

それはstrategy: mirrorを指定することで実現できるようです。

strategy: mirrorはGitLab 18.2で導入された機能です。

親パイプラインのtrigger-testジョブに指定して、パイプラインを実行してみます。

.gitlab-ci.yml
stages:
  - test

trigger-test:
  stage: test
  trigger:
    include:
      - local: child.yml
+   strategy: mirror

この状態だと、子パイプラインの失敗が親パイプラインにも反映した状態になりました。

まとめ

今回はGitLab CIのtriggerについて確認してみました。

ジョブの結果は気にしないが、非同期でジョブを動かしておきたいケースで使えそうな機能な気がしています。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?