Git Product home page Git Product logo

jenkins-pipeline's Introduction

jenkins-pipeline

Sample pipeline code for CI/CD pipelines in gopaddle using Jenkins

Pre-requisite

As a pre-requisite, an application must be deployed in gopaddle. Below flow chart gives the step by step process to be followed before creating a Jenkins pipeline.

Since we are building a pipeline for an application deployed in gopaddle, we must first initialize and deploy an application in gopaddle before we move on to creating the pipeline in Jenkins.

  • Subscribe to gopaddle - If you do not have a gopaddle subscription yet, subscribe to the gopaddle portal
  • Provision K8s in gopaddle
  • Add a Container Registry - Add a Container registry to gopaddle, to push or pull Docker images
  • Clone the project locally - Clone the GitHub project to be containerized.
  • Initialize and deploy the project using gopaddle
    • Download and install gpctl - Now, from your local desktop, download and install gpctl command line utility.
    • Perform gpctl init - Auto-generate the Dockerfile and Kubernetes YAML, build docker images, and deploy the application.
    • capture the .gp file with the resource IDs - Once the application is onboarded using gopaddle, gpctl init creates a .gp file in the project folder which contains the apiToken, containerID, serviceID, applicationID, projectID, releaseID and the distributionID. Make a note of these IDs, as we will be using these in the Jenkins pipeline script.

Creating pipeline in the Jenkins

  • select a New Item option in the Jenkins Dashboard.
  • Give the Name of the pipeline and select pipeline option in that window and click on OK to create the pipeline project.

  • select the Generic Webhook Trigger option under the Build Triggers menu. In the Generic Webhook Trigger window click the Post content parameters Add button. Using that add four variables serviceID, buildID, status, buildVersion. Add the variable name and expression
serviceID --> $.id 
buildID --> $.message.description.buildID 
status --> $.message.description.status
buildVersion --> $.message.description.buildVersion

  • Add a token for authenticate the webhook in the token part. and select Print contributed variables checkbox also for adding logs to console.

In the Groovy script first we check the status of the build. if the status is created then we have to rolling update the application in the gopaddle using API Token.

API: https://$endPoint/gateway/v1/$(projectID)/application/$(applicationID)

Method: PUT

Payload:

{
 "deploymentTemplateVersion": "draft",
  "serviceGroups": [
  	{
  		"name": "petclinic",
  		"description": "V2VsY29tZSBtZXNzYWdlIHVwZGF0ZWQ=",
  		"id": "serviceGroupID",
  		"version": "draft",
  		"services": [
  			{
  				"releaseConfig": {
  					"buildID": "'"$buildID"'",
  					"version": "'"$buildVersion"'"
  					
  				},
  				"id": "'"$serviceID"'",
  				"serviceVersion": "draft"
  			}
  		]
  	}
  ],
  "updateType": "buildUpdate"
}

It will update the build image version in the application in the gopaddle. but before trigger the build in the gopaddle, create the webhook notification using the webhook URL.

Go to gopaddle portal.

Click on the Notification.

Go to “HTTP Webhooks” tab.

Choose Type as Jenkins and use the below URL to register jenkins webhook notification.

http://<Jenkins_Domain>/generic-webhook-trigger/invoke?token=build-complete

Go to the alert page create New alert. select the container with BuildCreate option. now you can trigger the build to run the pipeline.

Maintainers

This sample template is maintained by the gopaddle.io team.

jenkins-pipeline's People

Contributors

gopaddle-io avatar logeshkrish avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.