並行ステップ オプション

並列ステップによって、一度に (同時に) 実行できるパイプライン ステップをグループ化して、ビルド時間を短縮できます。

概要

並列ステップのセットアップまたは実行

並行ステップを使用すると、自己完結型の一連のステップを同時に実行して、ビルドやテストを迅速に行えます。 ステップを並行した場合も、パイプラインが使用する合計のビルド時間数は変わりません。結果を早く確認できるようになりますが、使用した合計ビルド時間は、各ステップでかかった合計時間に基づいて計算されます。

この機能はさまざまな方法で使用できますが、次のガイドラインに従うことをお勧めします。

  1. ソフトウェアをビルドするための最初のステップを設定します。

  2. ソフトウェアをテストするための一連の並行ステップを追加します。
    複数の並行テスト ステップにつながる 1 つのビルド ステップを実行している場合、最初のステップで、外部ビルドの依存関係を可能な限り多くキャッシュすると、それぞれのテスト ステップ実行時の時間を節約できます。その後、すべてのテストを同時に実行します。テストはキャッシュを使用できます。

  3. 複数の類似環境に同時にデプロイします。

例:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 pipelines: default: - step: # non-parallel step script: - ./build.sh - parallel: # these 2 steps will run in parallel steps: - step: script: - ./integration-tests.sh --batch 1 - step: script: - ./integration-tests.sh --batch 2 - step: # non-parallel step script: - ./deploy.sh

並行ステップの既定変数

標準パイプライン変数に加えて、並列ステップ グループには次の既定変数も存在します。

  • BITBUCKET_PARALLEL_STEP - グループ内の現在のステップのゼロベース インデックス (例: 0、1、2…)。

  • BITBUCKET_PARALLEL_STEP_COUNT - グループ内のステップの合計数。

並行ステップの制限

  • パイプラインにおける 100 ステップの制限には、並行グループの各ステップも含まれます。

  • 並列ステップ セット内のすべての環境は同じタイプである必要があります。このため、同じセットに本番環境とテスト環境タイプを混在させないでください。

  • 並行ステップでは、アーティファクトを生成および消費できます。次の点に注意します。

    • 並行ステップでは、以前のステップで生成されたアーティファクトのみを使用できます。同じ並行セットのステップで生成されたものは使用できません。

    • 並行セットのあとのステップは、生成されたすべてのファイルの組み合わせを取得します。

    • ファイルを含むアーティファクトが並行ステップによって同じ場所に生成された場合、競合はファイル単位で解消され、YAML ファイルの最後のステップで生成されたファイルが優先されます。

並行ステップ オプション

並行ステップ グループを設定するには、次のオプションを使用できます。

parallel

parallel オプションでは、ステップのリストを同時に実行することで、コードの生成とテストを高速化できます。ステップを並行にした場合でも、パイプラインが使用するビルドの合計時間数は変わりませんが、結果はより早く表示されます。パイプライン定義に設定できるステップの合計数は、並列または単独のどちらで実行されているかにかかわらず、100 に制限されます。

並行ステップの使用方法の詳細については、「成功ステップの設定または実行」を参照してください。

プロパティparallel

必須 — いいえ

データ タイプ — 改行で区切られたキーと値のペアのブロック (YAML 仕様 - ブロック マッピング)

指定可能な親プロパティdefaultbranchespull-requeststagscustom

指定可能な子プロパティsteps (必須) と fail-fast

例 — parallel オプションを使用して、2 つのステップを同時に実行する

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 pipelines: default: - step: # sequential step name: Build script: - ./build.sh - step: # sequential step name: Build script: - ./build.sh - parallel: # these 2 steps will run in parallel steps: - step: name: Integration 1 script: - ./integration-tests.sh --batch 1 - step: name: Integration 2 script: - ./integration-tests.sh --batch 2 - step: # non-parallel step script: - ./deploy.sh

手順

steps プロパティには、stage または parallelstep のリストが含まれます。ステップ リストには少なくとも 1 つの step が必要です。

プロパティsteps

必須 — はい

データ タイプ — 改行で区切られたキーと値のペアのブロック (YAML 仕様 - ブロック マッピング)

指定可能な親プロパティparallelstage

指定可能な子プロパティstep (必須)

例 — step プロパティを使用して、並行グループのステップをリストする

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 pipelines: default: - step: # sequential step name: Build script: - ./build.sh - step: # sequential step name: Build script: - ./build.sh - parallel: # these 2 steps will run in parallel steps: - step: name: Integration 1 script: - ./integration-tests.sh --batch 1 - step: name: Integration 2 script: - ./integration-tests.sh --batch 2 - step: # non-parallel step script: - ./deploy.sh

例 — step プロパティを使用して、ステージのステップをリストする

1 2 3 4 5 6 7 8 9 10 11 12 13 pipelines: default: - stage: name: Build and test steps: - step: name: Build app script: - sh ./build-app.sh - step: name: Run unit tests script: - sh ./run-tests.sh

fail-fast

fail-fast は、すべての parallel ステップに適用することもできれば、並行ステップの特定の step に適用することもできます。

  • ステップに fail-fast: false が含まれる場合、並行グループ全体が停止することなく、ステップが失敗することがあります。

  • ステップに fail-fast: true が含まれる場合、ステップが失敗すると、並行グループ全体が停止します。

プロパティfail-fast

必須 — いいえ

データ タイプ — ブール値

指定可能な値true または false

既定値false

指定可能な親プロパティstepparallel

例 — fail-fast を使用して、いずれかのステップが失敗した時点で並行ステップを停止する

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 pipelines: default: - step: name: Build script: - ./build.sh - parallel: # these option alows to force stop all running steps if any step fails fail-fast: true steps: - step: name: Integration 1 script: - ./integration-tests.sh --batch 1 - step: name: Integration 2 script: - ./integration-tests.sh --batch 2

例 — fail-fast から並行ステップを除外する

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 pipelines: default: - step: name: Build script: - ./build.sh - parallel: # these option alows to force stop all running steps if any step fails fail-fast: true steps: - step: name: Integration 1 script: - ./integration-tests.sh --batch 1 - step: name: Integration 2 script: - ./integration-tests.sh --batch 2 - step: # option can be disabled for a step # and its failure won't stop other steps in a group fail-fast: false name: Upload metadata script: - ./upload-metadata.sh

その他のヘルプ