Job Configuration

Prerequisites

1. Project should be configured locally:

  • Build.gradle configured and signing certificates are created

  • Proguard rules are added

  • Successful assembling should be done locally for all build variants (development, release, staging with all build flavors). Please ensure, that you have tested development build variant, not debug.

2. Project is created.

3. Jobs are created for 3 branches: Development, Staging, Production. Each job must be named with following template: project-name_build-type. For example ‘Playsport_development’.

Configure Build Steps

0. Build steps are running from top to bottom one by one, therefore be sure that you are configuring build steps in right order.

1. Go to https://hudson.themindstudios.com/job/Android/job/project-name/job/project-name_build-variant/ -> Click 'Configure'.

2. Setup repository name and build parameters.

Screenshot

Screenshot

3. Check ‘Discard old builds’ checkbox and set ‘Max # of build to keep’. No need to keep all of them.

Screenshot

4. Set build parameters to allow assembling different build variants.

Screenshot

5. Set label expression "MindStudios Android".

Screenshot

6. Set ‘Repository URL’ and ‘Branch specifier’.

Screenshot

7. Configure build triggers. We need Jenkins assemble new build when new commit appeared in target branch.

  • Check Trigger builds remotely (e.g., from scripts) checkbox and set Authentication token using template: [project name]_[branch name].
  • Check Build when a change is pushed to GitLab. GitLab CI Service URL checkbox then check Push Events checkbox.
  • Go to https://git.themindstudios.com/android/project_name -> Settings -> Integrations.
  • Copy the webhook link from Build Triggers section to ‘URL’ field and add authentication token as request parameter.
  • Check Push events checkbox and click Add Webhook button.

Screenshot

Screenshot

8. Choose any console output color.

Screenshot

9. Set following steps in Build section:

  • Export licenses
  • Invoke Gradle script (use additional parameters like --stacktrace if needed)
  • Set environment variables to lowercase.

Screenshot

10. Add post build action ‘Archive the artifacts’ to set main build goal.

Screenshot

11. Add post build action ‘Execute script’, set flags shown below and add following shell script:

#!/bin/bash
Env=$(echo "$Environment" | tr '[:upper:]' '[:lower:]')

echo "BuildFileName=YourProjectName-$Env" > env.properties
echo "BuildFolder=$Env" >> env.properties
1
2
3
4
5

Screenshot

We need this properties to be saved locally for further usage while Fabric integration.

12. Add Inject environment variables post-build step in Execute script post-build action and set file path: env.properties

13. Add Fabric Beta integration with Upload apk to Fabric Beta plugin if needed.

  • Set Fabric API key and Fabric API secret (they are similar for all apps per account).

  • Set apk file path as shown on screenshot.

  • Set Testers group with Testers group alias

Screenshot

Screenshot

Note, that filename and file path could be changed. For example project that contains product flavors has additional folder with flavor name in its hierarchy. So set data you need to environment variables to be able to configure artifact path flexibly.

14. Add Slack integration with Slack notification plugin if needed. Use android.dev@themindstudios.com account for this purpose. Ask your team lead for access.

  • In Slack notification step click Advanced button.

Screenshot

  • Set Team Subdomain, Integration token and Project channel. Follow this tutorial. Follow this link with your own parameters: https://WORKSPACE_NAME.slack.com/apps/A0F7VRFKN-jenkins-ci

Screenshot

  • Make Test connection

15. Post build to Slack if needed. To archive this:

  • Add android.dev user to slack workspace and invite to channel android_builds.

  • Generate legacy token hereopen in new window.

  • Add post action step Execute Scripts. Note, that CSS could be missing in Execute shell text containers. Don't worry, it's normal.

  • Add post build step Execute shell.

  • Copy this script (change the argument like workspace, ProjectName and others for your own) to post build to channel android_builds:

curl -F file=@/Users/android/.jenkins/jobs/workspace/Android/ProjectName/JobName/app/build/outputs/apk/ApkFileName.apk -F channels=#android_builds -F token=LEGACY_TOKEN -F title=AnyTitleYouWant#${BUILD_NUMBER} https://slack.com/api/files.upload
1