Prerequisite
- Jenkins Installation - Refer my blog for Jenkins installation on AWS EKS using Helm
- Spinnaker Installation - Refer their official website for installation document https://www.spinnaker.io/setup/
- Jenkins-Spinnaker Integration - Refer my blog for integration setup between Jenkins and Spinnaker
Use-case example
Using Spinnaker we're deploying application to kubernetes cluster. For this, we've written kubernetes manifests file in spinnaker pipeline stages with namespace and version
of the application as variables. These values we might want from Jenkins for, namespace will be replaced by branch name of jenkins running the build and version will be replaced by version populated while running the build.
Example of such kubernetes manifest file
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: petclinic
namespace: 'petclinic-${trigger["properties"]["branch_name"]}'
spec:
replicas: 1
template:
metadata:
labels:
app: petclinic
name: petclinic
spec:
containers:
- image: imageName:${trigger["properties"]["version"]}
name: petclinic
Jenkins-Spinnaker Integration
-
First we'll create properties file in Jenkins containing our required parameteres - namespace and vesion and we need to archive the file in order to send to spinnaker.
For this, I'm using jenkins pipeline type job, hence writing code in Jenkinsfile to create the properties file.
Here application verion is variable defined in Jenkinsfile, then using
mvn, jgitver
I'm populating version and storing it into version variable, hence I can use it then further in other stages, for example here for spinnaker propery purpose Below is the code for samestage("Send Parameters To Spinnaker"){ steps{ sh """ echo "--- branch_name: "${env.BRANCH_NAME}" version: "${version}" " > spinnaker_properties.yaml """ archiveArtifacts artifacts: 'build_properties.yaml', fingerprint: true } }
- Now go to Spinnaker pipeline configuration > Automated trigger where we have integrated jenkins as per 3rd prerequisite > there in last option "Property File" - write down the name of the property file we created in previous step, which is on our case "spinnaker_properties.yaml" > save the configuration.
-
Now, we need to mention these properties variable in kubernetes manifest file as shown in above use-case example
namespace: 'petclinic-${trigger["properties"]["branch_name"]}' image: imageName:${trigger["properties"]["version"]}
And our setup is ready!! Now whenever jenkins build job will run > it will capture branch name and version > archive this file > trigger the spinnaker pipeline and send propery file to spinnaker > and spinnaker will populate the value from this propery file wherever mentioned as variables.
Comments
Post a Comment