Setup Jenkins
Create Jenkins user
Go to System preferences , then Users and Groups.
Create new Administratior user named Jenkins. You must make the system auto-login to Jenkins user by selecting login options and turning the auto-login on. Restart the system to login into Jenkins user account.
Setup environment
Because we installed fastlane from the administrator account we need to setup it here also
$ /usr/local/Caskroom/fastlane/latest/install
After that we need to setup .bashrc and .profile
.bashrc must looks like this:
export ANDROID_SDK_ROOT=/usr/local/opt/android-sdk
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH="$HOME/.fastlane/bin:$PATH"
and .profile:
source ~/.bashrc
Generate SSH Key
We need to generate SSH key which will be used later to authenticate Jenkins agains the repositories.
Follow the instructions from the link below to generate SSH key. Keep it with default id_rsa name, because Jenkins can load it automatically.
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
Setup Apple Developer
Login to the apple developer portal and generate development and production certificates for the continuous integration server, which will build and publish the iOS applications.
Kolibri will expect an environment variableFL_APPLE_USER - the email associated with configured profile. This can be done by injecting environment variable into the Jenkins job which will process the projects.
Next you must add the account credentials to the Fastlane credentials manager.
$ fastlane fastlane-credentials add --username [email protected]
Password: ***********
Credential [email protected]:*********** added to keychain.
Fastlane will use FL_APPLE_USER as a username when is trying to get credentials from the keystore, so make sure you setup same email into the fastlane credential manager and the environment variable.
Configure Android secrets
We are using fastlane plugin called Cryptex which store secrets encrypted on git repository similar to fastlane match. Kolibri Fastfile is configured before build and publish Android app to download java keystore for signing the app, inject ENV variables with the credentials and also to download Google Play Console API credentials JSON file.
Kolibri will expect an environment variable CRYPTEX_PASSWORD - password for decrypting the repository you specified when you initialize the cryptex plugin. This can be done by injecting environment variable into the Jenkins job which will process the projects.
Initialize Cryptex
From your Android project setup the secrets, but first initialize cryptex:
$ fastlane add_plugin cryptex
$ cryptex init
Follow the instructions then
Import secrets
appbranch must be a branch name of the app/team/company which you will use later for signing applications.
Import keystore file
$ cryptex --git_branch appbranch --type import --in keystore.jks --key android_keystore
Import keystore credentials
$ cryptex --git_branch appbranch --type import_env --hash '{"KEYSTORE_PASSWORD":"pass", "KEYSTORE_ALIAS":"alias", "KEYSTORE_ALIAS_PASSWORD":"aliaspassword"}' --key android_keystore
We recommend to import these ENV variables into Cryptex:
KEYSTORE_PASSWORDKEYSTORE_ALIASKEYSTORE_ALIAS_PASSWORD
Import Google Play Android Developer
$ cryptex --git_branch appbranch --type import --in googleplay.json --key android_google_play
Configure LaunchAgent
After Jenkins is installed successfully, follow the instructions to start Jenkins on login
$ cp -fv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents
If you want to configure Jenkins to launch on system startup, for all users on OS X, then copy the plist file to the system Launchd location instead.
$ sudo cp -fv /usr/local/opt/jenkins/*.plist /Library/LaunchDaemons
$ sudo chown `whoami` /Library/LaunchDaemons/homebrew.mxcl.jenkins.plist
Restarting Jenkins
If you have an older version of Jenkins and you are upgrading it, then you can restart it this way:
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
JAVA Options
Optionally you can add these java options to the plist :
<string>-Xms1G</string>
<string>-Xmx1G</string>
<string>-XX:+UseConcMarkSweepGC</string>
<string>-XX:+CMSClassUnloadingEnabled</string>
<string>-XX:MaxPermSize=256m</string>