Continuous Cross Platform Mobile App Development using Jenkins Build Server

41
CONTINUOUS CROSS PLATFORM MOBILE DEVELOPMENT WITH JENKINS ADAM PAXTON

Transcript of Continuous Cross Platform Mobile App Development using Jenkins Build Server

Page 1: Continuous Cross Platform Mobile App Development using Jenkins Build Server

CONTINUOUS CROSS PLATFORM MOBILE DEVELOPMENT WITH JENKINS

ADAM PAXTON

Page 2: Continuous Cross Platform Mobile App Development using Jenkins Build Server

PHOTO OP

SLIDES AND NOTES

bit.ly/jenkinsnotes

Page 3: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HELLO

ADAM PAXTON▸ Freelance Mobile App Developer polancomedia.com

▸ iOS, Android, Appcelerator Titanium

▸ Twitter: @adampax

▸ Github: adampax

Page 4: Continuous Cross Platform Mobile App Development using Jenkins Build Server

GOALS

WHAT WE WANT TO DO TODAY

▸ Will this help our team?

▸ Pros, cons for using Jenkins

▸ Alternatives

▸ Stuff we learned when setting it up.

▸ Be the boss!

Page 5: Continuous Cross Platform Mobile App Development using Jenkins Build Server

RUN THE APP, MAKE SURE THE TESTS PASS, BUILD IT FOR DISTRIBUTION, UPLOAD IT TO THE BUILD DISTRIBUTION SERVICE, EMAIL TESTERS. THEN DO IT ALL AGAIN FOR THE OTHER PLATFORM. AND THEN DO IT AGAIN TOMORROW FOR THE NEXT FEATURE OR BUG FIX.

- You, every single day

LET’S GET A BUILD OUT TO TEST…

Page 6: Continuous Cross Platform Mobile App Development using Jenkins Build Server

THAT’S NOT THE HALF OF IT

DON’T FORGET…

▸ Pull the latest commit?

▸ Are we doing unit tests? Did those run?

▸ Where are those keys?

▸ What version of Xcode did we build on last time?

▸ Which branch?

▸ What’s the password to the distribution service?

▸ Who needs this version sent to them?

▸ Where was the build from yesterday?

▸ Who did that build?

▸ What version of the sdk did they use?

▸ Wait, what was that password again?

▸ No, I meant the keystore password, sorry.

▸ Err, actually, the alias?

▸ I don’t know what it is, either.

▸ How do I run the tests?

Page 7: Continuous Cross Platform Mobile App Development using Jenkins Build Server

OK, LET’S MAKE SOMEONE THE BUILD MASTER.

THAT’S A LOT OF STUFF FOR ALL OF US TO REMEMBER

Page 8: Continuous Cross Platform Mobile App Development using Jenkins Build Server

LET’S HAVE ONE PERSON REMEMBER TO DO ALL THAT STUFF.

PROBLEM SOLVED, RIGHT?

▸ Sometimes multiple builds go out a day (then double that, since we are cross-platform devs).

▸ Takes our build master’s dev time, and is disruptive.

▸ Multiple people coordinating to do build.

▸ Sometimes we like to go home, or even take vacation!

Page 9: Continuous Cross Platform Mobile App Development using Jenkins Build Server

BUILD A ROBOT.THERE HAS TO BE A BETTER WAY

Page 10: Continuous Cross Platform Mobile App Development using Jenkins Build Server

FITTER HAPPIER

AUTOMATE THE TEDIOUS BITS

▸ Identify your workflow

▸ Start with the core ‘build’

▸ Expand forward and backward from there

Page 11: Continuous Cross Platform Mobile App Development using Jenkins Build Server

15 STEPS

CURRENT SETUP

PULL CHANGES FROM GIT

TEST IOSTEST

ANDROIDBUILD AD

HOCUPLOAD

IPAUPLOAD

APKEMAIL

TESTERS

Someone asks me

for a build

…So I ask build master

Build master tells me tests failed

,

back to step 1

So who should

get notified?

Do we need to sign the apk?

New devices for theprovisioning profile?

Page 12: Continuous Cross Platform Mobile App Development using Jenkins Build Server

THEN A SHEER DROP

MOVING TO THE BUILD SERVER

TEST IOS, ANDROIDBUILD AD HOC

Jobs

UPLOAD IPA, APKEMAIL TESTERS

Plugin

PULL CHANGES FROM GIT

Plugin

Build Server

Page 13: Continuous Cross Platform Mobile App Development using Jenkins Build Server

THEN A SHEER DROP

INTERACT WITH THE BUILD SERVER

Build Server

Trigger a build

Tell us if build failed

Send out the build! Excelsior!

Page 14: Continuous Cross Platform Mobile App Development using Jenkins Build Server

AUTOMATING WORKFLOW.WHAT ARE WE REALLY DOING?

Page 15: Continuous Cross Platform Mobile App Development using Jenkins Build Server

JIGSAW FALLING INTO PLACE

DOESN’T THIS FEEL FAMILIAR?

▸ We’re refactoring our workflow.

function doBuild(opts, success, error) { …}

Page 16: Continuous Cross Platform Mobile App Development using Jenkins Build Server

MORNING BELL

HOW TO START A BUILD

▸ Watch for changes to a repository

▸ At regular intervals, every x hours

▸ When another build completes

▸ Via URL, cURL POST

▸ etc.

Page 17: Continuous Cross Platform Mobile App Development using Jenkins Build Server

LET DOWN

TELL US IF BUILD FAILED

▸ Usually email logs to us

▸ What test failed?

▸ Blame the last commiter?

▸ Pretty much anything else you want

Page 18: Continuous Cross Platform Mobile App Development using Jenkins Build Server

FUL STOP

POST BUILD ACTIONS

▸ Upload to our build distribution service, email users

▸ Publish it?

▸ Trigger another build

▸ Anything else you want

Page 19: Continuous Cross Platform Mobile App Development using Jenkins Build Server

OK COMPUTER

WHAT WE NEED

▸ A way to have this stuff done for us

▸ We’re cross platform, so it has to build iOS and Android

▸ Mac for iOS

▸ Android, Java, stuff like that

▸ Whatever our x-platform tool requires, like Node.js

▸ We’re all remote, so has to be remotely accessible

Page 20: Continuous Cross Platform Mobile App Development using Jenkins Build Server

NO SURPRISES

HOW ABOUT JENKINS

▸ An automation server

▸ Open source, strong community

▸ Web admin

▸ Insanely flexible (can be overwhelming!)

▸ Probably already a plugin for what you need

▸ jenkins.io

Page 21: Continuous Cross Platform Mobile App Development using Jenkins Build Server

I MIGHT BE WRONG

CONS

▸ Every person’s setup is a unique snowflake

▸ Need to maintain the build server

▸ Flexibility can indeed be overwhelming

▸ Ramp up

Page 22: Continuous Cross Platform Mobile App Development using Jenkins Build Server

USING JENKINS.WHAT WORKED FOR US, AND WHAT DIDN’T.

Page 23: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

FIRST, SOME TERMINOLOGY

▸ Job/Project: Any task that you configure Jenkins to run

▸ Build: Result of one run of a job

▸ Build Trigger: How the build is started

▸ Build Step: An action performed by the build, such as run a command

▸ Post Build Action: What to do when build completes

▸ Workspace: Temporary working directory used for building a job.

▸ Plugin: Extend the functionality of Jenkins w/ core or 3rd party plugins

▸ Pipeline: New(ish)! Define an entire job with a script

Page 24: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

INSTALL

▸ A fairly recent Mac w/ latest OS

▸ Install Java 7 or 8 first

▸ Jenkins version 2 LTS

▸ Mac Installer

▸ Installs Applications/Jenkins/jenkins.war

▸ Creates a launch daemon that runs jenkins

▸ Creates a ‘jenkins’ user that runs the jobs/projects

▸ Puts configuration in users/shared/jenkins/home

Page 25: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

INSTALL

▸ Our first hurdle: the ‘jenkins’ user

▸ All jobs run as jenkins user, so it needs access to any sdks, folders, etc.

▸ Can either log in as the jenkins user to set up your dev environment, or do a lot of ‘sudo su’ and ‘chmod’

▸ Both options can work

Page 26: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

MORE INSTALLATION GOTCHAS

▸ Installing developer keys/certificates into keychain

▸ If connected via VNC /remote desktop, the password will fail silently

▸ Need to connect a physical keyboard to enter pw

▸ Using Node.js with nvm or n didn’t work for us, neither did Nodejs Jenkins plugin

▸ Installed node.js globally

▸ export PATH=“/usr/local/bin:$PATH" in any build step shell

Page 27: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

MOVE THE CORE BUILD

▸ Install your dev requirements

▸ Xcode

▸ Android sdks

▸ X-Platform sdk

▸ etc

▸ Make sure you can run a build manually, start to finish, as jenkins user

Page 28: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

THE WEB UI

▸ localhost:8080

▸ Jenkins 2 has improved the default security settings, prompting you to set up security during Setup Wizard

▸ Home page shows list of jobs and their stats

▸ Nav column for Managing jenkins, users, etc

Page 29: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

ON SECURITY

▸ Not wide-open by default anymore in v2

▸ Create accounts, add to group

▸ For job level access:

▸ ‘Project-based Matrix Authorization Strategy’ sounds a lot more complex than it really is

▸ Manage Jenkins > Configure Global Security

▸ Then set user/group access on each job

▸ Consider using VPN for remote access

Page 30: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

GLOBAL SETTINGS

▸ Manage Jenkins > Manage Plugins

▸ Github plugin (as opposed to just ‘git’ plugin)

▸ Mask Passwords plugin

▸ TestFairy Plugin

▸ wiki.jenkins-ci.org/display/JENKINS/Plugins

▸ Manage Jenkins > Configure System

▸ Configure email

▸ Git settings

Page 31: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

CREATING A JOB

▸ New Item > Freestyle Project

▸ Security

▸ Parameterized build?

▸ Prompt user for build inputs, or pass via url args

▸ use them as env variables $paramName

▸ SCM

▸ Build Triggers

▸ Build steps

▸ Post-build actions

Page 32: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

CONFIGURING A JOB

Page 33: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

SCM AND TRIGGERS

Page 34: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

BUILD STEPS

Page 35: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

POST BUILD

Page 36: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

AFTER A BUILD

▸ Check the build console output.

▸ You will do many of these.

Page 37: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

ALTERNATIVES

▸ Bamboo - Atlassian

▸ travis-ci.org

▸ circleci.com

▸ codeship.com

▸ buddybuild.com

Page 38: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

NEXT STEPS

▸ Keep automating more items when it makes sense

▸ Ongoing process

▸ fastlane.tools

▸ Pay attention to tests!

▸ Move scripts to source control

▸ Pipelines

Page 39: Continuous Cross Platform Mobile App Development using Jenkins Build Server

HOW WE USE JENKINS

WHAT WE LEARNED

▸ Complete automation or CI wasn’t always best for us

▸ Stepped back from having a commit trigger a build all the way to the user

▸ Making use of URL/params to trigger builds as needed

▸ We keep finding more stuff to automate

Page 40: Continuous Cross Platform Mobile App Development using Jenkins Build Server

EXIT MUSIC

TAKEAWAYS

▸ Teams of any size will benefit from automation

▸ Save time!

▸ More consistent testing and distribution

▸ Your workflow and methodologies will fit

▸ Start with the core build, move from there

▸ You will find more ways to automate, improve workflow

Page 41: Continuous Cross Platform Mobile App Development using Jenkins Build Server

THANKSAdamis bit.ly/jenkinsnotesCool