パイプラインタスクが実行されるたびに、新しいインスタンスがスケジュールされます。 タスクの実行がコードリポジトリのコードに依存する場合は、タスクが実行されるたびにビルド用のコードを手動でプルする必要があります。 コミュニティは、コードの取得を高速化するためのチェックアウトプラグインを提供します。 このトピックでは、チェックアウトプラグインを使用してビルド用のコードをダウンロードする方法について説明します。
チェックアウトプラグインの使用方法
Serverless-cdコミュニティは、ビルド用のコードをプルするためのチェックアウトプラグインを提供します。 チェックアウトプラグインは、サーバーレスアプリケーションセンターのロジックに適合しており、ビルドプロセスをトリガーするGitイベントに対応するコードバージョンを自動的に取得します。
実行コンテキストでのコードプルの設定を定義する
Serverless Application Centerで作成されたパイプラインは、実行コンテキストのGitイベントに対応するコードバージョンのプルモードを自動的に設定します。 サンプルコード:
---
# Submit the pipeline for execution.
kind: Pipeline
name: "p-<% .git.shortCommitId %>-<% .currentTimestampMs %>"
# The description.
description: cached pipeline
spec:
context:
data:
# Serverless Application Center automatically populates this section after triggered.
checkout:
provider: "gitlab"
remote: "https:*:*//gitlab.com/*/*.git"
ref: "+*:refs/remotes/origin/master"
token: "*"
userName: "*"
branch: "master"
commit: "*"
templateName: mytemplate-<% .git.branch %>
---
チェックアウトプラグインをステップで使用
パイプラインテンプレートまたはタスクテンプレートでは、コンテキストステップを実行してチェックアウト部品を使用できます。 一般に、最初のステップではチェックアウトプラグインが必要です。 プラグインが実行されると、指定されたコードバージョンがオンプレミスのコンピューターにプルされます。 ユーザーは、プルされたコードに基づいてアクションを実行できます。 サンプルコード:
---
kind: PipelineTemplate
name: mytemplate-<% .git.branch %>
description: cached pipelinetemplate
spec:
context:
data:
envName: test
deployFile: s.yaml
tasks:
# Build and deploy.
- name: build-and-deploy
context:
data:
enable: true
steps:
# Pull code.
- plugin: "@serverless-cd/checkout"
# Initialize Serverless Devs.
- plugin: "@serverless-cd/s-setup"
# Use other plug-ins or scripts to perform actions.
# - run: make build && make deploy
# - plugin: "@serverless-cd/others"
taskTemplate: serverless-runner-task
---