Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Oct 07, 2019 12:44

You can use the Gradle plugin as part of a Jenkins CI controlled job. This section guides you through the process of integrating your automation scripts with Jenkins based on your use case.

IMPORTANT: The steps provided here only apply to Espresso and XCUITest. With these frameworks, an app is installed as part of the Perfecto Gradle plugin. If you install an app directly from Jenkins, you need to use the REST API to upload it to the repository (see Upload item to repository) and, in a second step, install it on a device (see Install application).

Scenario 1 | Android Studio

An Android Studio (AS) project folder is hosted in a Git Repository that is accessible to Jenkins. The AS project is already configured to work with the Gradle plugin, meaning the build.gradle files and config.json file are defined properly, as described in the Use the Gradle plugin in Android Studio Project. The Gradle wrapper is included in the AS project.

  1. Create a new Jenkins Job.
  2. Add the Source Code Management information for the Git repository location of the project.
  3. Add the build step using the Gradle wrapper application from the AS project to activate the plugin.
  4. Run the job and get the Gradle output in the console logs.

Scenario 2 | Standalone mode with Gradle plugin

You run Gradle from Jenkins using the Jenkins Gradle plugin. For Android, application debug and Espresso-test apk files exist in the local file system. For iOS, application, XCTest, XCUITest ipa files exist in the local file system.

  1. Create a new parameterized Jenkins job
    The Job uses the Perfecto Lab URL, Security token, "build.gradle" file, and configuration file as parameters to the job.
  2. Add a String parameter with your Perfecto Lab URL as default
  3. Add a String parameter with your security token as default
  4. To make the build.gradle file and plugin configuration file more dynamic, add their content as Multi-line String parameters and then create the files during the job build 

    "build.gradle" example (used in the above dialog):

    buildscript {
        repositories {
    		maven {
                url ""
        dependencies {
            classpath "com.perfectomobile.instrumentedtest.gradleplugin:plugin:+"
    apply plugin: 'com.perfectomobile.instrumentedtest.gradleplugin'

    Configuration file example (dialog above presents a parallel Android example):

      "devices": [
          "platformVersion": "1[01]\..*"
      "tags" : ["test_1","test2"],
      "projectName" : "UITest",
      "projectVersion" : "v10.5-test",
      "branch" : "master"
  5. (For Android) Add the apk and test apk files as File parameters with the location ./app-debug.apk and ./app-debug-androidTest.apk, 
    (For iOS) Add the application ipa and UI test ipa runner files as File parameters with the location ./app.ipa and ./app-tests-runner.ipa,
    these files may also be passed from a different job or download them from a remote repository. 
  6. In the build section we create the "build.gradle" and "config.json" files according to the parameters we've received above in two "Execute shell" build steps
  7. Add an "Invoke gradle script" where we run the plugin task with the command. Add also the Job name and Build number in the command these allow you to filter the specific tests in the reports.

    Android example
    perfecto-android-inst -PcloudURL=$CLOUD_URL -PsecurityToken=$SECURITY_TOKEN -PconfigFileLocation=config.json -PapkPath=app-debug.apk -PtestApkPath=app-debug-androidTest.apk -PjobName=${JOB_NAME} -PjobNumber=${BUILD_NUMBER}
    iOS Example
    perfecto-xctest -PcloudURL=$CLOUD_URL -PsecurityToken=$SECURITY_TOKEN -PconfigFileLocation=config.json -PappPath=app-debug.ipa -PtestAppPath=app-debug-UITest.ipa -PjobName=${JOB_NAME} -PjobNumber=${BUILD_NUMBER}

    Run the job and get the Gradle output in the console logs

Scenario 3 | Standalone mode with Gradle wrapper

Same as Scenario 2 but without the Jenkins Gradle plugin. Instead, you run an installed version of the Gradle wrapper.

  1. Perform Steps 1-6 as described in Scenario 2.
  2. Add another Execute shell build step to the Jenkins project.
  3. Add the command to execute the Gradle wrapper, for example:

    Android Example
    /root/gradlew perfecto-android-inst -PcloudURL=$CLOUD_URL -PsecurityToken=$SECURITY_TOKEN -PconfigFileLocation=config.json -PapkPath=app-debug.apk -PtestApkPath=app-debug-androidTest.apk
    iOS Example
    /root/gradlew perfecto-xctest -PcloudURL=$CLOUD_URL -PsecurityToken=$SECURITY_TOKEN -PconfigFileLocation=config.json -PappPath=app-debug.ipa -PtestAppPath=app-debug-UITest.ipa

    where: /root/gradlew is the full path to the gradle wrapper executable.

  4. Run the job as in the previous scenario. The output is sent to the console.