Skip to main content

Send Jenkins Parameters to Spinnaker

Prerequisite

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 same

                        
    stage("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

Popular posts from this blog

Install InfluxDB on AWS EKS using Helm

Create namespace for influxdb kubectl create ns influxdb We'll store InfluxDB data on AWS EBS as persistent storage, hence for that create storage class apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: influxdb provisioner: kubernetes.io/aws-ebs parameters: type: gp2 fsType: ext4 allowVolumeExpansion: true Install using Helm - In this command we've set few values like namespace, service type, storageclass and its size helm install influxdb stable/influxdb --namespace influxdb --set service.type=LoadBalancer,persistence.enabled=true,persistence.storageClass=influxdb,persistence.size=...

How to clone Github repository using SSH

Run ssh-keygen Upload ssh public key to github account curl -u "gitUsername:password" --data '{"title":"keyName","key":"'"$(cat ~/.ssh/id_rsa.pub)"'"}' https://api.github.com/user/keys Sample output of ssh public key upload command { "id": 1234567890, "key": "ssh-rsa aaaaaaaaaaaaaaaaaaaa/dddd/+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "url": "https://api.github.com/user/keys/123456...

How to read user's input in Bash Script

Create shell script file as below: #!/bin/bash echo "Enter your name!" read name echo "Welcome to Mars $name" Make script file executable chmod u+x test.sh Run script sh test.sh Output of the script: Enter your name! Rectangle Welcome to Mars Rectangle