Continuous Integration and Deployment (CI/CD) for mobile apps (Appcelerator)

Introduction

The purpose of this document is to give a step by step approach for installing a continuous integration and continuous build server. This document will cover end to end instructions in getting code from a developer’s environment to the application delivery server for testers to download and test against. This will also include testing the code using the Jasmine test suite and building each platforms ( ipa, .apk) files.
What this is not

  • Instructions on how to build a test suite with Jasmine
  • Recommendation on the type of server configuration such as hardware/VM requirements (RAM, HD).
  • Covering unsupported versions, future or past, of the Axway Appcelerator SDK.
  • Will only cover a basic setup of Jenkins and not a detailed approach to every aspect of the software.
  • Details on publishing applications to Apple’s App Store or Google Play Store.
  • Details on how to use Github tokens or webhooks

 

Required Accounts and Prerequisites

You will need a valid Apple ID and developer license to install XCode and manage your provisioning files. You also need a valid Axway Appcelerator account to download and install the SDK.
You will need OS 10.10.X or above running on

  • Macintosh hardware
  • Or VM of the Mac OS.

Software

The following software will be needed on the build server. It is however important that you install them in order. Not installing them in the order specified in this document may cause some issues with user permissions. All versions of the software should be the latest versions available unless specified.

  • Java 6, 8
  • Jenkins
  • Node.js
  • xCode

Steps

It is important that these steps are done in order. This will avoid any issues with user permissions regarding Jenkins.

Java

Make sure you have these versions of Java installed
Java 6
https://support.apple.com/kb/dl1572?locale=en_US
Java 8 se dev
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
 

Jenkins setup and user promotion

Download and install, follow set up instructions
https://jenkins.io/download/
In a command prompt do the following in order to get the initial password
$ sudo su - Jenkins
$ cat /Users/Shared/Jenkins/Home/secrets/initialAdminPassword
Setting up the Jenkins user and promote it to an admin.
Make the Jenkins user automatically login when the computer is restarted:

  1. Go to System Preferences\Users & Groups.
  2. Unlock the settings by clicking the lock in the bottom left corner of the page and entering the login password for the current user.
  3. Select the Jenkins user from the list of users. Note: On our install, the Jenkins user shows up as empty in the list of available users. To fix this, right-click the empty user and select Advanced Options… which will show you details on the user. Set the Full Name to Jenkins and press OK.

Give it a full name.

  1. Click Reset Password. Create a new password for the Jenkins user, and make sure to take note of it somewhere secure. This is just like any other Mac user login that has admin access, and should be treated as such.
  2. Select Login Options underneath the list of users.
  3. Select Automatic login and choose Jenkins.
  4. Enter the password you just created for the new Jenkins user.
  5. Restart your computer. Once finished, you should be automatically logged in as the OSX Jenkins user.

 

Allow Jenkins to Run GUI Applications

By default, Jenkins is unable to run GUI applications because it runs as a Daemon. A daemon runs in the background as part of the overall system, and isn’t tied to a specific user. This would be like having a butler that couldn’t interact with anyone. Sure it could clean up after us, but what about answering the door or fetching my martini!
A big part of CI is running simulators and other GUI applications, so we’ll need another option. To fix this, you can change Jenkins to run as a Launch Agent. A launch agent runs in the background on behalf of a user.
 
To change how the Jenkins process is launched, you’ll need to edit the settings file and change its location so it will automatically start on reboots.
 
Enter the following command to unload Jenkins as a Daemon: $ sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
 
Next, move the. plist file, which defines how Jenkins will run, to the LaunchAgents folder: $ sudo mv /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchAgents/
 
The default .plist file that Jenkins creates adds a key-value pair called SessionCreate. This creates issues when running certain applications, such as iOS simulators. The reason for this? Honestly, I’m not sure. In the past, a fix to many Jenkins CI issues in the iOS world was to add this key manually. It seems that with Xcode 6 things have reversed and it’s now required that you remove the key which solves the issue. Open the file with the editor of your choosing, and remove them.
 
$ sudo vim /Library/LaunchAgents/org.jenkins-ci.plist
 

/* Remove the following lines */
<key>SessionCreate</key
<true />
/* Save the file */

Lastly, reload the Launch Agent to restart Jenkins.
$ sudo launchctl load /Library/LaunchAgents/org.jenkins-ci.plist
Keep Those Fingers Crossed

Now, restart your computer and make sure that Jenkins successfully starts on its own after the reboot. If working correctly, your Mac should automatically login to the Jenkins user.

Login as Jenkins user

Install xCode from App Store (* Run once after install to finalize install)

Install Node.js

https://nodejs.org/en/

Install Appcelerator cli

$ sudo npm install appcelerator -g
– Update Appc to install latest version
$ appc init

Install Titanium

$ npm install titanium -g
$ appc ti sdk install

Install Android

Download android tools
https://developer.android.com/studio/index.html
Download platform tools
https://developer.android.com/studio/releases/platform-tools.html
Download NDK
https://developer.android.com/ndk/downloads/index.html
 
Create directory and unzip the tools into the android-sdk-macosx folder
$ mkdir /Users/Shared/Jenkins/Library/android-sdk-macosx
$ cd /Users/Shared/Jenkins/Library/android-sdk-macosx
To install the latest Android SDK
$ titanium setup android
Use Paths when asked
/Users/Shared/Jenkins/Library/android-sdk-macosx
/Users/Shared/Jenkins/Library/android-sdk-macosx/[NDK FOLDER NAME]
 
NOTE: When you do your first build, and hyperloop error, fix it by creating a new project on the build server with hyperloop to install modules then just delete it. $ appc new
 
If you get the error file already exists symlink, delete the build folder
 
Install android SDK build tools (use latest)
 
(example: $ ./sdkmanager "build-tools;26.0.1”)
 
Install platform 23 (optional but may be needed)
$ ./sdkmanager "platforms;android-23"
 

Jenkins Setup

Login with your credentials

  • Under Manage Jenkins set up SCM (e.x. github) hooks
  • Generate a new job (see Jenkins doc for details)
  • Point to your build script
#!/bin/bash
source /Users/Shared/Jenkins/Documents/jenkins.sh


Add build script and set permissions $ chmod +x /Users/Shared/Jenkins/Documents/jenkins.sh

Example script jenkins.sh

#!/bin/bash
echo "pulling latest"
git -C /Users/Shared/Jenkins/Documents/AutomatedBuildTest pull
export PATH="/usr/local/bin:${PATH}"
jasmine-node /Users/Shared/Jenkins/Documents/AutomatedBuildTest/spec/jasmine_examples/PlayerSpec.js

#BUILDS AND DEPLOYS ANDROID .apk
# appc run -p android -T dist-playstore [-K <KEYSTORE_FILE> -P <KEYSTORE_PASSWORD> -L <KEYSTORE_ALIAS> -O <OUTPUT_DIRECTORY>]
appc run -d /Users/Shared/Jenkins/Documents/AutomatedBuildTest -p android -T dist-playstore -K ~/.android/android.keystore -P ****** -O ~/Desktop -b --app-preview --release-notes='Automated Build Android' --invite=dmason@axway.com --notify='Devs,QA'

#BUILDS AND DEPLOYS IOS .ipa
# NOTE RUN $ appc info to get the ids for provision file, and cert
#appc run -p ios -T dist-adhoc [-R <DISTRIBUTION_CERTIFICATE_NAME> -P <PROVISIONING_PROFILE_UUID> -O <OUTPUT_DIRECTORY>]
appc run -d /Users/Shared/Jenkins/Documents/AutomatedBuildTest -p ios -T dist-adhoc -R ‘Axway Software’ -P ‘c11b6587-ddc1-421d-a209-4f1893110054’ -O ~/Desktop -b --app-preview --release-notes='Automated Build iOS' --invite=dmason@axway.com --notify='Devs,QA’

Github

  • Generate personal access token and set up webhooks url
  • Clone project to shared location $ cd /Users/Shared/Jenkins/Documents/
  • Clone project $ git clone [YOUR PROJECT URL]
    (example $ git clone https://github.com/djmason9/AutomatedBuildTest.git)

Jenkins Freestyle Project Setup

Create a New Item in Jenkins
Select Freestyle project
Point to your project

 
Add your repository link

 
Set up your hooks

 

Jasmine-node

Install Jasmin and Jasmin-node globally
$ npm install -g jasmine
$ npm install -g jasmine-node

Android adhoc setup

Create key store for Android
$ mkdir ~/.android
$ keytool -genkeypair -v -keystore path/file_name -alias alias_name -keyalg RSA -sigalg SHA1withRSA -validity 10000
(example: $ keytool -genkeypair -v -keystore ~/.android/android.keystore -alias testingKey -keyalg RSA -sigalg SHA1withRSA -validity 10000)
check key
$ keytool -list -v -keystore path/file_name
(example: $ keytool -list -v -keystore ~/.android/android.keystore )
Build packages
$ touch ~/.android/repositories.cfg
$ cd ~/Library/android-sdk-macosx/tools/bin
$ ./sdkmanager "system-images;android-23;google_apis;x86"
Build Android APK file (should be in script)
$ cd /Users/Shared/Jenkins/Documents/[YOUR PROJECT]
(example: $ cd /Users/Shared/Jenkins/Documents/AutomatedBuildTest)

$ appc run -p android -T dist-playstore [-K <KEYSTORE_FILE> -P <KEYSTORE_PASSWORD> -L <KEYSTORE_ALIAS> -O

]

( example : $ appc run -p android -T dist-playstore -K ~/.android/android.keystore -P ******* -O ~/Desktop)

iOS

Create a Distribution certificate for your build machine.
Create a CSR file.
In the Applications folder on your Mac, open the Utilities folder and launch Keychain Access.
Within the Keychain Access drop down menu, select Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority.

  • In the Certificate Information window, enter the following information:
  • In the User Email Address field, enter your email address.
  • In the Common Name field, create a name for your private key (e.g., John Doe Dev Key).
  • The CA Email Address field should be left empty.
  • In the “Request is” group, select the “Saved to disk” option.
  • Click Continue within Keychain Access to complete the CSR generating process.

 
Create a new iOS Certificate for the build machine using your newly created

 
Download and add to your keychain login

 
Create a new App Id (if you haven’t already)

 
Create a new adHoc Provisioning Profile (if you haven’t already)

 

xCode (in order to grab all your provision files)

  • Log into Xcode and download provision file.
  • To check that they are installed run $ appc info

First Build

Before your first build log into appc with command line $ appc login follow instructions

App Preview

The first time you run the build you might need to manually set up users to notify on subsequent builds.

Helpful Links

Command line help for adhoc builds
http://docs.appcelerator.com/platform/latest/#!/guide/Appcelerator_CLI_Tasks-section-src-43306725_AppceleratorCLITasks-iOSAdHocDistribution
 
App Preview location and documentation
https://appbeta.appcelerator.com/
http://docs.appcelerator.com/platform/latest/ – !/guide/App_Preview
 
CLI Command Tasks Documentation
http://docs.appcelerator.com/platform/latest/ – !/guide/Appcelerator_CLI_Tasks
http://docs.appcelerator.com/platform/latest/ – !/guide/Appcelerator_Command-Line_Interface_Reference
http://docs.appcelerator.com/platform/latest/ – !/guide/Titanium_Command-Line_Interface_Reference
 
Distributing iOS and Android
http://docs.appcelerator.com/platform/latest/ – !/guide/Distributing_iOS_apps
http://docs.appcelerator.com/platform/latest/ – !/guide/Distributing_Android_apps
 
Example Project
https://github.com/djmason9/AutomatedBuildTest

Loading Facebook Comments ...