Skip to content

Latest commit

 

History

History
142 lines (84 loc) · 7.2 KB

JENKINS.md

File metadata and controls

142 lines (84 loc) · 7.2 KB

Jenkins

How to install Jenkins

Download Jenkins and follow the installing instructions. It shouldn't be tricky.

Must have plugins for Android project

Optional

Environment variables

In order to build the project we need to have environment variables set in Jenkins (Manage Jenkins -> Configure system -> Global properties -> Environment variables):

How to create Jenkins job with clone/build/test/analyse/notify actions:

  1. Create job with Freestyle type:

  2. Configure source code management section:

  3. Configure webhooks/polling:

    In order to build the project automatically when changes are pushed to the remote repository webhook should be configured. How to create a webhook.

    If 2fa is enabled on github, then it will not be possible to configure webhook as mentioned in previous link. Polling might be used as an alternative in this case.

  4. Configure Android emulator for UI tests. It will be started automatically during the build:

    Startup delay isn't mandatory. In order to start Android emulator during the build ensure that all required Android targets and ABI's installed on Jenkins node.

    android list targets command shows "Available Android targets".

  5. Configure how the project will be built using Gradle build scripts

    In "Tasks" section we need to specify a list of Gradle tasks to be invoked.

    For example: clean connectedAndroidTest assembleDebug testDebug jacocoTestReport checkstyle pmd jdepend lintDebug buildDashboard -PversionCode=${BUILD_NUMBER} -PfabricApiKey="YOUR_KEY" -PfabricApiSecret="YOUR_SECRET"

  6. Configure reports

    Make sure JaCoCo exclusions match JaCoCo project configuration.

  7. Configure APK distribution to Fabric Beta

  8. Configure email notifications

Bonus: Jenkins job described above can be easily created using jenkins/config.xml file.

  1. Check Jenkins HOME directory structure to have better understanding where Jenkins keeps jobs.
  2. Create subdirectory in JENKINS_HOME/jobs and copy config.xml file there.
  3. Restart jenkins (https://YOUR_JENKINS_SERVER_URL/restart) to apply the changes.
  4. Configure the job with missing secret keys (Fabric API key & secret, etc.)

Jenkins Pipeline

Not all plugins are compatible with Pipeline plugin. Check COMPATIBILITY document for complete information.

jenkins/Jenkinsfile contains Pipeline job configuration. It contains clone/build/test/analyse/notify steps as a regular job.

Secret keys must be exported on the Jenkins node or set directly in Jenkinsfile or passed as build parameters like

env.FABRIC_API_KEY = "${FABRIC_API_KEY}"
env.FABRIC_API_SECRET = "${FABRIC_API_SECRET}"

How to create Pipeline job:

  1. Create job with Pipeline type

  2. Configure build parameters

  3. Add Pipeline script or use from Jenkinsfile

  4. Build the project by pushing it to remote repository or manually

Install/Update Android SDK

Different Android project might use different Android SDK versions and build tools. These should be installed on the build machine. Having 2 jobs in Jenkins which help with Android dependencies installation should be enough:

  1. install_specific_android_sdk.sh - This will install specific Android SDK on the build machine. Create parametrized job with content of this shell script and SDK_LIST String parameter (comma-separated Android SDK versions).

  2. update_android_sdk.sh - This will update/install all Android SDK versions. Create parametrized job with content of this shell script and schedule periodic builds of this job. Would be nice to execute this job every night to make sure that build machine has latest Android SDK versions installed. To achieve that we need to enable periodic midnight builds - Build Triggers -> Build periodically -> @midnight.