Salesforce DX Pipeline Jenkins Shared Library Copyright 2019
Salesforce DX Pipeline Jenkins Shared Library Copyright © 2019 - Claim. Vantage
About Me Hi, I’m Jeferson • Software Developer since 2004, started with Java, worked with a few other stacks but my main experience is with Microsoft C#. • Salesforce Certified Platform Developer I with 5+ years of experience ranging from Lightning Platform, Sales Cloud, Service Cloud and Integrations.
Who we are Claim. Vantage is a leading international provider of life, health, and absence claim management software solutions to insurance carriers, TPAs, and employers. Copyright © 2019 - Claim. Vantage
Agenda • Why? • What are Jenkins Pipeline Shared Libraries? • How many builds automated? • Demo • Library Testing • Lessons Learned • What is next? • Contributing Copyright © 2019 - Claim. Vantage
Why? 1. To avoid duplication o How would you help teams to avoid duplicating configurations? What about establishing guidelines? 2. To simplify testing against various org configurations 3. Provide a Domain-Specific Language o We don’t expect all devs to be Jenkins experts but all the teams are expected to get up and running fairly quick. Copyright © 2019 - Claim. Vantage
Starting Point (simplified) Total from original: 76 lines #!groovy import groovy. json. Json. Slurper. Classic node { def JPK = env. JENKINS_PRIVATE_KEY_ID def HUB_ORG = env. HUB_ORG_DH def SFDC_HOST = env. SFDC_HOST_DH def JWT_KEY_CRED_ID = env. JWT_CRED_ID_DH def CONNECTED_APP_CONSUMER_KEY = env. CONNECTED_APP_CONSUMER_KEY_DH stage('Checkout source') { checkout scm } with. Credentials([file(credentials. Id: JWT_KEY_CRED_ID, variable: 'jwt_key_file')]) { stage('Create Scratch Org’) { rc = sh return. Status: true, script: "sfdx force: auth: jwt: grant --clientid ${CONNECTED_APP_CONSUMER_KEY} --username ${HUB_ORG} –jwtkeyfile ${jwt_key_file} --setdefaultdevhubusername --instanceurl ${SFDC_HOST}" rmsg = sh return. Stdout: true, script: "sfdx force: org: create --definitionfile config/project-scratch-def. json --setdefaultusername” def robj = new Json. Slurper. Classic(). parse. Text(rmsg) } } Copyright © 2019 - Claim. Vantage
Next projects migrated Project #3 165 lines Project #2 134 lines Project #4 171 lines Copyright © 2019 - Claim. Vantage
Copyright © 2019 - Claim. Vantage
Multiple scratch org configuration o Person Accounts (PA) turned on o Shield Platform Encryption (SPE) turned on o PA and SPE turned on o Enhanced Notes o Make all the combinations Copyright © 2019 - Claim. Vantage
Copyright © 2019 - Claim. Vantage
Multiple scratch org configuration • Now are you willing to run them in sequential order? • What if your master branch took 2. 5 h to build for each config? • What about 5 different combinations? Copyright © 2019 - Claim. Vantage
Copyright © 2019 - Claim. Vantage
What are Jenkins Pipelines Shared Libraries? • Pipeline has support for creating "Shared Libraries" which can be defined in external source control repositories and loaded into existing Pipelines. • They are usually written in Groovy using different data structures, utility methods, and may include other pipeline steps (e. g. sh, git). Source: https: //jenkins. io/doc/book/pipeline/shared-libraries/ Copyright © 2019 - Claim. Vantage
Copyright © 2019 - Claim. Vantage
How many builds automated? By February 2019: 18 and growing.
Copyright © 2019 - Claim. Vantage
Demo • How to add into the Global Pipeline Libraries • How to add a reference • How the builds look
Library Testing • Unit Tests are implemented using Jenkins Pipeline Unit Testing framework. • Started simple with no unit test and initial tests cover the compilation, thus need more work. • Challenge: Jenkins have no standard test framework and different approaches still keep the conversation live – see Jenkins-33925. • The main tests are our own builds! Copyright © 2019 - Claim. Vantage
Lessons Learned • Jenkins Pipelines can do the job! • We don’t need to repeat ourselves. • CI relies on a bunch of plugins. • There are multiple approaches to test shared libraries. • We don’t need to re-authenticate the Dev Hub on every build (better to authenticate once). Copyright © 2019 - Claim. Vantage
What is next? • Second-generation packaging. • Retrieve package installation keys from Credentials using a pattern. Copyright © 2019 - Claim. Vantage
Contributing • Pick or create an issue. • Clone from https: //git. io/fh. NMP. • Send a pull request. Copyright © 2019 - Claim. Vantage
Questions?
Jeferson Chaves https: //www. linkedin. com/in/jefersonchaves/
- Slides: 23