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

How to skip resources, compiler, surfire, install plugin in maven's default build process

When we want to use maven command line to upload zip type artifact to artifact repository then we don't want resources, compiler, surefire, install phases in maven process, only assembly would be enough. To skip particular phases go to each plugin's original website phase according to latest running plugin version download the same to our own project refer the skip phase configuration of particular phase, either it can be done command line or as part of the build-plugin-configuration. Example using POM.xml file <project> [...] <build> <plugins> <plugin> <groupId...

Install AWS CLI on Ubuntu localhost using Ansible Playbook

Install AWS CLI on Ubuntu localhost using Ansible Playbook --- - hosts: localhost tasks: - name: Installing Unzip package package: name: unzip state: present when: ansible_facts['os_family'] == "Debian" become: true - name: Create awscli directory in home directory file: path: ~/awscli state: directory mode: '0755' - name: Download bundled installer zip file get_url: url: https://s3.amazonaws.com/aws-cli/awscli-bundle.zip dest: ~/awscli/awscli-bundle.zip - name: Extract zip file unarchive: src: ~/awscli/awscli-bundle.zip dest: ~/awscli - name: Run install command shell: /home/ubuntu/awscli/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws become: true Same script is also avail...

How to give permission to particular user to particular dir. or file in Linux

Permission error: ubuntu@ip-192-168-62-113:~/bbb/testing$ ls -ltrh total 4.0K -rwx------ 1 ubuntu ubuntu 70 Mar 18 09:43 test.sh ubuntu@ip-192-168-62-113:~/bbb/testing$ sudo su - abc abc@ip-192-168-62-113:~$ cat /home/ubuntu/jaydeep/testing/test.sh cat: /home/ubuntu/bbb/testing/test.sh: Permission denied Command - how to give permission to particular user to particular dir. or file ubuntu@ip-192-168-62-113:~/bbb/testing$ sudo setfacl -m u:abc:r test.sh ubuntu@ip-192-168-62-113:~/bbb/testing$ sudo su - abc abc@ip-192-168-62-113:~$ cat /home/ubuntu/bbb/testing/test.sh #!/bin/bash read -p "What is your name? " name echo "Welcome $name!" For the Directory setfacl -m u:userID:rwx /dir/subdir/ setfacl -m u:userID:rwx /d...