> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/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 リクエストを送信します。

<br />

<br />

```mermaid theme={null}
flowchart LR
  Event[Artifact alias added]
  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>

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 リクエストが届くはずです。

## Go further

* [Automation events and scopes](/models/automations/automation-events) for all project and registry event types.
* [Create a Slack automation](/models/automations/create-automations/slack) and [Create a webhook automation](/models/automations/create-automations/webhook) for full UI and payload details.
