Overview
This article will discuss how to introduce declarative configurable parameters to your Jenkinsfile build job. We will be tying these parameters into the Salesforce SFDX Deploy Stage of our build. The goal of this is to have a very diverse way to kick of builds from different Git branches and to different Salesforce environments as well.
Prerequisites
+ Jenkins Server with a Multibranch Pipeline job sync'd with your favorite vcs
+ SFDX CLI
Step 1
First taking a look at the parameters section of the build file. We've included different parameters to ultimately construct our sfdx force:source:deploy command
We can install a Git parameter plugin on out Jenkins server to pull in available branches for us. That gives the us the ability to specify the "gitParameter" param as shown above.
https://plugins.jenkins.io/git-parameter/
Now that we have supplied parameters to our Jenkinsfile we get the option from the Jenkins server to launch the "build with parameters". Here we can easily configure and kick off our build declaratively. This can be a helpful tool for testing new feature branches of isolated code against the greater code base in a upstream Salesforce environment.
Lets now take a look at the SF Deploy stage of our build file where we will take the user supplied parameters to construct our deployment with the SFDX CLI
Some key points here is the logic to check what caused the build, either a manual user "Build with Parameters" or a Branch even such as a push or pull request.
Conclusion
Thats all there is to it! Now you can spin up some new Jenkins users and open up access to Dev and QA members to build and test out different jobs from a declarative configuration screen in Jenkins.
Finally here is a simplified Jenkinsfile with just the basics related to this article
https://gist.github.com/nickforce/99f9ea6fe6418999d1c7e70fe74787a8
Resources
https://plugins.jenkins.io/git-parameter/
https://developer.salesforce.com/tools/sfdxcli
https://gist.github.com/nickforce/99f9ea6fe6418999d1c7e70fe74787a8
No comments:
Post a Comment