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

Jenkins 連携

  • ダーク
    ライト

Article Summary

Autify ではお手持ちのJenkins workflow から簡単にビルドをアップロードしたりテストプランを実行できる公式のJenkins plugin を提供しています。

Getting started

はじめてみよう

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

前提条件

まず、すでにJenkins Project やPipeline を使ってアプリケーションのビルドを行なっているものとします。そのビルドstep のすぐ後にAutify のテストを実行するstep を追加することで、新しくビルドされたアプリケーションがエンドツーエンドのユーザ体験を損ねていないことを確認できるようにします。

次に、Autify for Mobile でテストプランを作成する必要があります。テストプランまたはシナリオのURL (例: https://mobile-app.autify.com/projects/AAA/scenarios/BBB) をメモしておいてください、後ほど利用します。

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

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

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" には任意の名前を付けられます。ここではautifyMobileAccessToken と命名したと仮定しておきます:

Screen Shot 2022-09-15 at 6.46.30 PM.png

Autify for Mobile にビルドをアップロードしたりテストを実行するbuild step を追加

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

Jenkins Project

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

Screen Shot 2022-09-15 at 7.56.45 PM.png

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

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


新しいビルドファイルをアップロードしてテストを開始する (テストの完了は待たない)
Screen Shot 2022-09-15 at 6.47.50 PM.png

もしテストが完了するか、タイムアウトするまで待つ場合:
Screen Shot 2022-09-15 at 6.48.05 PM.png

新しいビルドファイルをアップロードするだけであれば、"Upload build to Autify for Mobile" ビルドstep が使えます (workspace-id は上でメモしたURL の/projects/ のすぐ後ろのidです):

Screen Shot 2022-09-15 at 7.58.02 PM.png

Screen Shot 2022-09-15 at 7.57.47 PM.png

Jenkins Pipeline

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


新しいビルドファイルをアップロードしてテストを開始する (テストの完了は待たない)

autifyMobile credentialsId: 'autifyMobileAccessToken', autifyUrl: 'https://mobile-app.autify.com/projects/AAA/test_plans/BBB', buildPath: 'path/to/your-[ios.app|android.apk]'

もしテストが完了するか、タイムアウトするまで待つ場合:

autifyMobile credentialsId: 'autifyMobileAccessToken', autifyUrl: 'https://mobile-app.autify.com/projects/AAA/test_plans/BBB', buildPath: 'path/to/your-[ios.app|android.apk]', wait: true

新しいビルドファイルをアップロードするだけ (workspaceId は上でメモしたURL の/projects/ のすぐ後ろのid):

autifyMobileUpload credentialsId: 'autifyMobileAccessToken', workspaceId: 'AAA', buildPath: 'path/to/your-[ios.app|android.apk]'

(非推奨) "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_MOBILE_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 mobile test run https://mobile-app.autify.com/projects/AAA/test_plans/BBB --build-path path/to/your-[ios.app|android.apk]
      
    • Jenkins Pipeline:
      1. shwithCredentials で囲んで以下の様に追加します:
      withCredentials([string(credentialsId: 'autifyMobileAccessToken', variable: 'AUTIFY_MOBILE_ACCESS_TOKEN')]) {
          sh '''
          curl https://autify-cli-assets.s3.amazonaws.com/autify-cli/channels/stable/install-cicd.bash | bash -xe
          ./autify/bin/autify mobile test run https://mobile-app.autify.com/projects/AAA/test_plans/BBB --build-path path/to/your-[ios.app|android.apk]
          '''
      }
      

注: shell step 内のAutify CLI のコマンドはお好きな様にカスタマイズできます。詳しくはAutify CLI のドキュメント をご覧ください。

まとめ

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


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

What's Next
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.