Setup a Jenkins CI pipeline
Assuming the repository has been configured correctly, including setup of SonarCloud and Snyk, the following steps should be followed to setup a Jenkins CI pipeline.
Create bounded context folder
Each service should group it's CI pipelines in a Jenkins folder matching the name of the bounded context. This is to ensure that the Jenkins UI remains manageable as the number of services grows.
For example, a repository named ffc-pay-enrichment would be placed in a folder named ffc-pay.
If a bounded context folder does not exist, create one by:
- navigating to the Jenkins home page
- select
New Item - enter the
item namein the formatffc-<bounded context>, for exampleffc-pay - select
Folder - select
Ok
Create a build pipeline
- navigate to your bounded context folder in Jenkins
- select
New Item - enter the
item namein the format<repository name>-build, for exampleffc-demo-web-build - select
Multibranch Pipeline - select
Ok - enter
GitHubas a Branch Source - for credentials select the
github-tokenwith theffcplatformuser - enter your GitHub URL in the
HTTPS URLfield, for examplehttps://github.com/DEFRA/ffc-demo-web.git - set
Discover branchestoAll branches - delete
Discover pull requests from originandDiscover pull requests from forks - set
Scan Multibranch Pipeline Triggers -> Periodically if not otherwise runtotruewith an interval of1 hour - set
Pipeline Action Triggers -> Pipeline Delete Eventsetffc-housekeeping/cleanup-on-branch-delete - set
Pipeline Action Triggers -> Include Filterto be* - set
Pipeline Action Triggers -> Additional Parameter -> Parameter Nameto berepoNameandParameter Valueto be the name of the repository, for example,ffc-demo-web
Definitions can be copied from existing pipelines. To save time, when creating a new pipeline select
Copy fromand enter the name of an existing pipeline. Remember to update therepoNameandGitHub URLfields.
Create a deployment pipeline
Although Azure DevOps is used for deployments, Jenkins is used to trigger the deployment pipeline following the successful run of a main branch build.
The deployment to the Sandpit environment is also orchestrated by Jenkins.
- navigate to your bounded context folder in Jenkins
- select
New Item - enter the
item namein the format<repository name>-deploy, for exampleffc-demo-web-deploy - select
Pipeline - select
Ok - select
This project is parameterized - add the following parameters:
environmentwith a default value ofsndnamespacewith a default value of<bounded context>chartNamewith a default value of<repository name>chartVersionwith a default value of1.0.0helmChartRepoTypewith a default value ofacr- select
Trigger builds remotely (e.g., from scripts) - enter
Authentication tokenwhich can be found in any existing deployment pipeline - enter the below script in the
Pipelinesection with aDefinitionofPipeline script
@Library('defra-library@v-9') _
deployToCluster environment: params.environment,
namespace: params.namespace,
chartName: params.chartName,
chartVersion: params.chartVersion,
helmChartRepoType: params.helmChartRepoType
Test the pipeline
Commits to both feature branches and main branches should trigger the build pipeline. Successful builds of the main branch should trigger the deployment pipeline.
Following deployment the new service should be available in the Sandpit AKS cluster in a namespace matching the bounded context. For example, ffc-demo-web would be deployed to the ffc-demo namespace.
The specific steps that run during the pipeline are based on the content of the repository assuming it follows the standard structure.
Builds can also be triggered manually by selecting
Build Nowfrom the pipeline page.