パイプラインのアーティファクト

はじめに

アーティファクトは、ステップによって作成されるファイルです。パイプライン設定で定義したら、以降のステップで共有したり、エクスポートしてステップの完了後にアーティファクトを保持したりすることができます。たとえば、ビルド ステップで生成された JAR ファイルまたはレポートを、後のデプロイメント ステップで使用できます。ステップで生成されたアーティファクトをダウンロードしたり、外部ストレージにアップロードすることもできます。

次の点に留意する必要があります。

  • ステップの最後に BITBUCKET_CLONE_DIR にあるファイルをアーティファクトとして構成できます。BITBUCKET_CLONE_DIR は、リポジトリが最初にクローンされるディレクトリです。

  • glob パターンを使用してアーティファクトを定義できます。* で開始される glob パターンは、引用句で囲む必要があります。: これらは glob パターンのため、パス セグメント "." および “..” は使用できません。ビルド ディレクトリに相対的なパスを使用します。

  • Artifact paths are relative to the BITBUCKET_CLONE_DIR.

  • ステップ中に作成されたアーティファクトは、以降のすべてのステップで使用できます。

  • 並行ステップで作成されたアーティファクトは、同じ並行ステップのグループ内の他のステップからはアクセスできない場合があります。並行グループ内の別のステップがアーティファクトを要求した場合、要求された時点で存在する可能性もあれば、存在しない可能性もあります。

  • アーティファクトは生成から 14 日後に削除されます。

  • By default, all available artifacts are downloaded at the start of a step. You can control this behavior using the download field:

    • Set download: true to download all artifacts from previous steps.

    • Set download: false to skip downloading any artifacts.

    • Set download to a list of specific artifact names to download only those artifacts. Be sure to specify the exact artifact names. For example, to download artifacts with names Artifact 1 and Artifact 2, use:

      download: - "Artifact 1" - "Artifact 2"

Artifact types

Artifact types identify artifacts with distinct behaviour.

The following artifact types are available:

  • Shared artifacts: Accessible across multiple steps. Use shared artifacts for workflows that require sharing data between steps.

  • Scoped artifacts: Scoped to each step and can’t be downloaded across steps. Scoped artifacts are ideal for files like log-files, test reports, screenshots, or videos generated during testing.

Using artifact types is optional, but specifying them can help you save build minutes and improve artifact organization.

Artifact fields for shared and scoped artifacts

When uploading shared or scoped artifacts in Pipelines, provide details using the following fields:

  • Name (required): The name of the artifact displayed in the user interface.

  • Type: The artifact type—either shared or scoped. The default is shared.

  • Paths (required): A list of glob patterns to include as artifacts.

  • Ignore-paths: A list of glob patterns to exclude from artifacts.

  • Depth: The maximum depth to search for artifacts in the file hierarchy. By default, the search includes the entire hierarchy.

  • Capture-on: The step condition for uploading the artifact. Possible values are:

    • success: Upload the artifact if the step passes.

    • failed: Upload the artifact if the step fails.

    • always: Upload the artifact regardless of the step outcome (default).

Define artifact types under the upload section within the artifacts section of your YAML file.

アーティファクトの使用

以降の bitbucket-pipelines.yml ファイルの例は、アーティファクトをステップ間で共有するように設定する方法を示しています。

  • "Build and test" スクリプトが完了すると、dist フォルダと report フォルダ (いずれも BITBUCKET_CLONE_DIR にあります) のすべての txt ファイルが同じパスでアーティファクトとして保持されます。

  • "Integration test" と "Deploy to beanstalk" は、最初のステップで作成された dist および reports のファイルにアクセスできます。

  • "Integration test" が dist または reports へのすべての変更は、"Integration test" でアーティファクトとして指定されていないため、後のステップでは利用できません。変更を保持したい場合、このステップでそれらもアーティファクトとして定義する必要があります。

  • アーティファクトはダウンロードされないため、「成功メッセージを表示」中は利用できません。このステップではアーティファクト success.txt が作成されて、後のステップでダウンロードできるようになります。

  • When the ‘Run post deployment tests’ step completes:

    • all files in the test-reports folder—except for HTML files—are saved as a shared artifact and made available to subsequent steps

    • files in the logs folder are saved as a scoped artifact if the step fails; these scoped artifacts are not passed to later steps

  • In the final step, ‘Run coverage report’, only the reports/*.txt and pdv-test-reports artifacts from previous steps are downloaded. This targeted download helps reduce build minutes by avoiding unnecessary artifact downloads.

  • 特定のステップでダウンロードされたアーティファクトの既定のファイル権限は 644 (-rw-r--r--) に設定されています。パイプなど、実行されるコマンドに応じてこれらの権限を変更する必要がある場合があります。

アーティファクトには 1 GB のサイズ制限があります。

bitbucket-pipelines.yml の例

pipelines: default: - step: name: Build and test image: node:10.15.0 caches: - node script: - npm install - npm test - npm run build artifacts: # defining the artifacts to be passed to each future step. - dist/** - reports/*.txt - step: name: Integration test image: node:10.15.0 caches: - node services: - postgres script: # using one of the artifacts from the previous step - cat reports/tests.txt - npm run integration-test - step: name: Deploy to beanstalk image: python:3.5.1 script: - python deploy-to-beanstalk.py - step: name: Display success message artifacts: download: false # do not download artifacts in this step paths: # defining artifacts to be passed to each future step - success.txt script: - echo "Deployment for $BITBUCKET_COMMIT successful!" > success.txt - step: name: Run post deployment tests caches: - node script: - npm run pdv-tests artifacts: upload: - name: pdv-test-reports #shared artifact type: shared paths: - test-reports/** ignore-paths: - test-reports/*.html - name: pdv logs #scoped artifact type: scoped paths: - "logs/**" capture-on: failed - step: name: Run coverage report caches: - node artifacts: download: #download only specific artifacts defined in previous steps - reports/*.txt - pdv-test-reports script: - npm run coverage-report definitions: services: postgres: image: postgres:9.6.4

手動ステップ

手動ステップでは自動ステップと同様、過去のあらゆるステップで作成されたビルド アーティファクトが作業ディレクトリにコピーされます。

アーティファクトのダウンロードと有効期限

ステップで生成されたアーティファクトをダウンロードできます。

  1. パイプラインの結果ビューの [アーティファクト] タブを選択します。

  2. ダウンロード アイコンをクリックします。

アーティファクトは、アーティファクトを生成したステップの完了後 14 日間保持されます。この期間が過ぎるとアーティファクトは期限切れとなり、パイプラインでは以降のあらゆる手動ステップを実行できなくなります。

アーティファクトを 14 日間以上保持したり、1 GB 以上のアーティファクトを保持したりする場合、Amazon S3 やホスト型のアーティファクト リポジトリ (JFrog Artifactory など) のような独自のストレージ ソリューションを使用することをお勧めします。アーティファクトのビルドの保持期間の制限は、コストを管理できる範囲に抑えることで、Pipelines でのビルド アーティファクトの保管および転送料金を発生させないために行っています。

詳細については、次の情報をご参照ください。

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。