> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wandb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# チュートリアル: Registry artifact エイリアス のオートメーション

> Registry artifact に "production" などの特定の エイリアス が付いたときに webhook を実行するオートメーションを作成します。

このチュートリアルでは、artifact のメタデータによってトリガーされる **Registry** オートメーションの構築方法を説明します。Registry 内の artifact に特定のエイリアス (たとえば **本番**) が付与されると、W\&B は webhook に `POST` リクエストを送信します。モデルを既知のステージに昇格させるたびに、このパターンを使用して deployment パイプライン、ページングサービス、通知チャネルなどの下流システムに通知できます。このチュートリアルは、W\&B Registry でモデルのライフサイクルを管理する ML エンジニアや MLOps の実務担当者を対象としています。

<br />

<br />

```mermaid theme={null}
flowchart LR
  Event[Artifact エイリアスが追加されました]
  Action[Webhook]
  Event --> Action
```

<br />

<Tip>project オートメーションの作成手順については、[チュートリアル: project の run 失敗アラート オートメーション](/ja/models/automations/project-automation-tutorial)を参照してください。</Tip>

<div id="prerequisites">
  ## 前提条件
</div>

* **Team Settings** で設定済みの [webhook](/ja/models/automations/create-automations/webhook#create-a-webhook)。
* 少なくとも 1 つのコレクションを含む W\&B の [Registry](/ja/models/registry/create_registry) (既存の Registry を再利用してもかまいません) 。

<div id="create-a-registry-automation">
  ## Registry のオートメーションを作成する
</div>

Registry スコープのオートメーションを設定します。このオートメーションでは、その Registry 内の任意のコレクションにある artifact に特定の エイリアス (たとえば **production**) が付与されると、W\&B から webhook に `POST` リクエストが送信されます。

1. Registry を開き、**Automations** タブをクリックしてから **Create automation** をクリックします。
2. イベント **An artifact エイリアス is added** を選択します。対象の エイリアス に一致する **Alias regex** を入力します (例: **production** または **staging**) 。
3. **Next step** をクリックします。**Action type** を **Webhooks** に設定し、webhook を選択します。webhook がペイロードを想定している場合は、JSON 本文を貼り付け、`${artifact_collection_name}` や `${artifact_version_string}` などの [payload variables](/ja/models/automations/create-automations/webhook#payload-variables) を使用します。
4. **Next step** をクリックします。オートメーションの名前と任意の説明を入力し、**Create automation** をクリックします。

詳細は、[Create a webhook automation](/ja/models/automations/create-automations/webhook#create-an-automation) (Registry タブ) を参照してください。

<div id="test-the-automation">
  ## オートメーションをテストする
</div>

オートメーションがエンドツーエンドで実行されることを確認するには、artifact バージョンにエイリアスを追加して、設定したイベントをトリガーします。W\&B App または public API を使用して、Registry 内の artifact バージョンに エイリアス (たとえば **本番**) を追加します。例:

```python theme={null}
import wandb

with wandb.init(project="my-project") as run:
    artifact = wandb.Artifact("my-model", type="model")
    # ... 必要に応じてファイルまたはメタデータをartifactにログする ...
    run.log_artifact(artifact)
    run.wait()  # artifactのログが完了するまで待機する

# コレクションの最新バージョンにaliasを追加する
api = wandb.Api()
collection = api.artifact_collection(name="my-model", type_name="model")
version = next(collection.versions())  # 最新バージョンを取得する

version.aliases.append("production")
version.save()
print("Added alias 'production' to", version.name)

```

しばらくすると、webhook エンドポイントは、設定したペイロードを含む `POST` を受信します。これで、この Registry 内の artifact に一致する エイリアス が適用されるたびに起動する Registry オートメーションが動作するようになりました。

<div id="go-further">
  ## さらに詳しく
</div>

このチュートリアルで扱った内容を超えて W\&B のオートメーションについて詳しく知るには、以下のリソースを参照してください。

* [オートメーションのイベントとスコープ](/ja/models/automations/automation-events) では、すべての project および Registry のイベントタイプを確認できます。
* [Slack オートメーションを作成する](/ja/models/automations/create-automations/slack) と [webhook オートメーションを作成する](/ja/models/automations/create-automations/webhook) では、UI と payload の詳細を確認できます。
