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 name
in 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 name
in the format<repository name>-build
, for exampleffc-demo-web-build
- select
Multibranch Pipeline
- select
Ok
- enter
GitHub
as a Branch Source - for credentials select the
github-token
with theffcplatform
user - enter your GitHub URL in the
HTTPS URL
field, for examplehttps://github.com/DEFRA/ffc-demo-web.git
- set
Discover branches
toAll branches
- delete
Discover pull requests from origin
andDiscover pull requests from forks
- set
Scan Multibranch Pipeline Triggers -> Periodically if not otherwise run
totrue
with an interval of1 hour
- set
Pipeline Action Triggers -> Pipeline Delete Event
setffc-housekeeping/cleanup-on-branch-delete
- set
Pipeline Action Triggers -> Include Filter
to be*
- set
Pipeline Action Triggers -> Additional Parameter -> Parameter Name
to berepoName
andParameter Value
to 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 from
and enter the name of an existing pipeline. Remember to update therepoName
andGitHub URL
fields.
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 name
in the format<repository name>-deploy
, for exampleffc-demo-web-deploy
- select
Pipeline
- select
Ok
- select
This project is parameterized
- add the following parameters:
environment
with a default value ofsnd
namespace
with a default value of<bounded context>
chartName
with a default value of<repository name>
chartVersion
with a default value of1.0.0
helmChartRepoType
with a default value ofacr
- select
Trigger builds remotely (e.g., from scripts)
- enter
Authentication token
which can be found in any existing deployment pipeline - enter the below script in the
Pipeline
section with aDefinition
ofPipeline 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 Now
from the pipeline page.