> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/autify-university/integrations/jenkins-integration.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Jenkins 連携

Autify ではお手持ちのJenkins workflow から簡単にテストプランやシナリオを実行できる[公式のJenkins plugin](https://plugins.jenkins.io/autify/) を提供しています。

## はじめてみよう

このドキュメントでは、どのように[Autify Jenkins plugin](https://plugins.jenkins.io/autify/) を利用するかを順に説明していきます。

### 前提条件

まず、すでにJenkins Project やPipeline を使ってステージングやプロダクション等へのソフトウェアのデプロイを行なっているものとします。そのデプロイstep のすぐ後にAutify のテストを実行するstep を追加することで、新しくデプロイされたソフトウェアがエンドツーエンドのユーザ体験を損ねていないことを確認できるようにします。

次に、[Autify NoCode Web](https://app.autify.com) でテストプランかテストシナリオを作成する必要があります。テストシナリオは、そのJenkins でソフトウェアがデプロイされるウェブサイトに対してレコーディングすることになります。テストプランまたはシナリオのURL (例: `https://app.autify.com/projects/00/scenarios/000`) をメモしておいてください、後ほど利用します。

さらに、[パーソナルアクセストークンを生成する](https://help.autify.com/nocode-web/autify-university/integrations/integrate-with-api.md#issue-a-personal-access-token)必要があります。後ほどJenkins Secrets に保存するために、生成されたトークンはどこかにメモしておいて下さい。

{% hint style="warning" %}
**パーソナルアクセストークン**

パーソナルアクセストークンは1人のユーザに紐づいてしまうので、CI/CD 連携のために組織にマシンユーザを作って、そのパーソナルアクセストークンを使うことをお勧めします。
{% endhint %}

### Plugin をインストールする

[Autify Plugin のページ](https://plugins.jenkins.io/autify/) を開き、右上の"How to install" をクリックします。以下の様なインストールの選択肢が表示されます:

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-d8c069b8cf6f659c252e77e5ef9c8167160e92fd%2FScreen%20Shot%202022-08-12%20at%209.46.25%20AM.png?alt=media)

### パーソナルアクセストークンをJenkins Secrets に保存

上で生成したパーソナルアクセストークンを[Jenkins のドキュメント](https://www.jenkins.io/doc/book/using/using-credentials/)に従って、Secrets に保存します。"Kind" には **"Secret text" を使って**、"ID" には任意の名前を付けられます。ここでは`autifyWebAccessToken` と命名したと仮定しておきます:

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-97fe792ad9288966f5702bec4ee30a484af5d6f8%2FScreen%20Shot%202022-08-08%20at%205.05.04%20PM.png?alt=media)

### Autify for Web を実行するbuild step を追加する

それではお手持ちのJenkins Project またはPipeline に新しいstep を追加しましょう。

#### Jenkins Project

お手持ちのProject のconfiguration に行き、"Build" の下にある"Add build step"をクリックし、"Run test on Autify for Web" を選択します:

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-53343ff84279a74ed89d76c5ed28c6ecbd236fa0%2FScreen%20Shot%202022-08-09%20at%203.21.56%20PM.png?alt=media)

そうしたら、"Personal Access Token of Autify for Web" のセレクトボックスから上で作成したSecret のID (例: `autifyWebAccessToken`)を選択し、"Autify for Web test URL" には上で記録したURL (例: `https://app.autify.com/projects/00/scenarios/000`) を貼り付けます。

以下の例をご覧ください。

***

シンプルにテストを開始してstep を終了 (テストの完了は待たない):

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-c36886f6799ada5d165de94405d29e9db5aaf5ef%2FScreen%20Shot%202022-08-11%20at%204.42.09%20PM.png?alt=media)

テストを開始して、それが完了するかタイムアウトするまで待つ - "Wait?" をチェックします:

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-0fbd3b368b71229f84969debb36ca44d5a2c2b69%2FScreen%20Shot%202022-08-12%20at%2012.06.03%20AM.png?alt=media)

"URL replacements" を使ってテストプラン又はシナリオを別のURL に対して開始する - "Advanced" をクリックし"URL replacements" の"Add" をクリックします:

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-68e92e8b090dc8f317154a5b7f41ac23123a839a%2FScreen%20Shot%202022-08-12%20at%2012.06.38%20AM.png?alt=media)

*"URL replacements" はステージングのウェブサイトに対してプロダクションのウェブサイトで記録したテストシナリオを実行したい時などに有効です。*

#### Jenkins Pipeline

お手持ちの`Jenkinsfile` またはPipeline のconfiguration ページを開き、以下の様なstep をデプロイのstep の直後に追加します。

***

シンプルにテストを開始してstep を終了 (テストの完了は待たない):

```groovy
autifyWeb credentialsId: 'autifyWebAccessToken', autifyUrl: 'https://app.autify.com/projects/00/scenarios/000'
```

テストを開始して、それが完了するかタイムアウトするまで待つ:

```groovy
autifyWeb credentialsId: 'autifyWebAccessToken', autifyUrl: 'https://app.autify.com/projects/00/scenarios/000', wait: true
```

`urlReplacements` を使ってテストプラン又はシナリオを別のURL に対して開始する:

```groovy
autifyWeb credentialsId: 'autifyWebAccessToken', autifyUrl: 'https://app.autify.com/projects/00/scenarios/000', urlReplacements: [[patternUrl: 'http://example.com', replacementUrl: 'http://example.net']]
```

*`urlReplacements` はステージングのウェブサイトに対してプロダクションのウェブサイトで記録したテストシナリオを実行したい時などに有効です。*

### (非推奨) "Execute shell" step を利用

{% hint style="warning" %}
**もしAutifyが提供する Jenkins plugin を利用したくないか、plugin に問題がある場合は、代わりに"Execute shell" step を利用することができます。**
{% endhint %}

以下に手順をまとめています:

1. もしまだであれば、以下のplugin をインストールします:
   * [Credentials](https://plugins.jenkins.io/credentials/)
   * [Plain Credentials](https://plugins.jenkins.io/plain-credentials/)
   * [Credentials Binding](https://plugins.jenkins.io/credentials-binding/)
2. パーソナルアクセストークンを上に書いてあるように保存します。
3. "Execute shell" build step を追加します:
   * Jenkins Project:

     1. Secret を"Build Environment" > "Bindings" に追加します ("Variable" には`AUTIFY_WEB_ACCESS_TOKEN` を使います)
     2. "Execute shell" build step を以下の様に追加します:

     ```shell
     curl https://autify-cli-assets.s3.amazonaws.com/autify-cli/channels/stable/install-cicd.bash | bash -xe
     ./autify/bin/autify web test run https://app.autify.com/projects/00/scenarios/000
     ```
   * Jenkins Pipeline:

     1. `sh` を`withCredentials` で囲んで以下の様に追加します:

     ```groovy
     withCredentials([string(credentialsId: 'autifyWebAccessToken', variable: 'AUTIFY_WEB_ACCESS_TOKEN')]) {
         sh '''
         curl https://autify-cli-assets.s3.amazonaws.com/autify-cli/channels/stable/install-cicd.bash | bash -xe
         ./autify/bin/autify web test run https://app.autify.com/projects/00/scenarios/000
         '''
     }
     ```

注: shell step 内のAutify CLI のコマンドはお好きな様にカスタマイズできます。詳しくは[Autify CLI のドキュメント](https://help.autify.com/nocode-web/autify-university/integrations/autify-command-line-interface.md) をご覧ください。

## まとめ

[Autify のJenkins plugin](https://plugins.jenkins.io/autify/) (またはshell step)を使うことで、デプロイ後にテストプランやシナリオの実行を自動化できるので、無駄な時間を使うことなくリグレッションをすぐに検知して適切な行動を取ることができるようになります。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-web/autify-university/integrations/jenkins-integration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
