Jenkins 連携
  • 17 Aug 2022
  • 1 分で読めます
  • 投稿者
  • ダーク
    ライト

Jenkins 連携

  • ダーク
    ライト

Article Summary

Autify ではお手持ちのJenkins workflow から簡単にテストプランやシナリオを実行できる公式のJenkins plugin を提供しています。

はじめてみよう

このドキュメントでは、どのようにAutify Jenkins plugin を利用するかを順に説明していきます。

前提条件

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

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

さらに、パーソナルアクセストークンを生成する必要があります。後ほどJenkins Secrets に保存するために、生成されたトークンはどこかにメモしておいて下さい。

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

最後に、現時点ではLinux かmacOS 上で動いているJenkins のみをサポートしています。Windows 対応は検討中です。

Plugin をインストールする

Autify Plugin のページ を開き、右上の"How to install" をクリックします。以下の様なインストールの選択肢が表示されます:

Screen Shot 2022-08-12 at 9.46.25 AM.png

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

上で生成したパーソナルアクセストークンをJenkins のドキュメントに従って、Secrets に保存します。"Kind" には "Secret text" を使って、"ID" には任意の名前を付けられます。ここではautifyWebAccessToken と命名したと仮定しておきます:

Screen Shot 2022-08-08 at 5.05.04 PM.png

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

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

Jenkins Project

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

Screen Shot 2022-08-09 at 3.21.56 PM.png

そうしたら、"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 を終了 (テストの完了は待たない):

Screen Shot 2022-08-11 at 4.42.09 PM.png

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

Screen Shot 2022-08-12 at 12.06.03 AM.png

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

Screen Shot 2022-08-12 at 12.06.38 AM.png

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

Jenkins Pipeline

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


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

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

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

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

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

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 を利用

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

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

  1. もしまだであれば、以下のplugin をインストールします:
  2. パーソナルアクセストークンを上に書いてあるように保存します。
  3. "Execute shell" build step を追加します:
    • Jenkins Project:
      1. Secret を"Build Environment" > "Bindings" に追加します ("Variable" にはAUTIFY_WEB_ACCESS_TOKEN を使います)
      2. "Execute shell" build step を以下の様に追加します:
      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. shwithCredentials で囲んで以下の様に追加します:
      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 のドキュメント をご覧ください。

まとめ

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


この記事は役に立ちましたか?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.