GithubHelp home page GithubHelp logo

ivamsi2001 / jenkins-pipelines Goto Github PK

View Code? Open in Web Editor NEW

This project forked from colinbut/jenkins-pipelines

0.0 1.0 0.0 120 KB

A collection of different types of Jenkinsfile (Pipeline as Code)

Groovy 79.43% Dockerfile 0.29% Java 20.28%

jenkins-pipelines's Introduction

Jenkins Pipelines

The purpose of this project is for me to collect and hold a "library" of different Jenkins Pipelines. It also demonstrates numerous different ways to implement the pipelines.

Most noticeability:

  • Declarative Style
  • Scripted Style
  • Using a Jenkins Shared Library

Rather than configuring Jenkins Build Job configuration on the Web UI directly, code them in code files (.groovy) based on the Groovy DSL Syntax. This feature showcases the Pipeline As Code philosophy.

Pipeline

This project does not aim to demonstrate every single pipeline feature it has but merely serves as a personal go to repo for examples & demonstration purposes. To explore what Jenkins Pipeline Syntax has to offer fully, need to refer to its official documentation: https://www.jenkins.io/doc/book/pipeline/syntax/#post

Example App

As part of this demo jenkins pipelines library project, an example app is provided along with this for playing and testing the various different kinds of pipelines. It is a simple Java 8-Spring Boot app (one that is borrowed from one of my other personal side projects).

Declarative Pipelines

Declarative pipelines are a new syntax for Jenkins pipeline that came in later editions of Jenkins 2.0+

They aim to offer a more simplifed way of constructing pipelines as code which they follow a specific and yet rigid structure. Less flexible though.

e.g.

pipeline {
    agent any
    stages {
        stage("Compile") {
            steps {
                sh "./mvnw clean compile"
            }
        }
        stage("Unit Tests") {
            steps {
                sh "./mvnw test"
            }
        }
        stage("Integration Tests") {
            steps {
                sh "./mvnw verify"
            }
        }
        stage("Package") {
            steps {
                sh "./mvnw package -DskipTests=true"
            }
        }
    }
    post {
        always {
            echo "The build ${env.JOB_NAME} #${env.BUILD_NUMBER} has finished"
        }
        failure {
            echo "The build ${env.JOB_NAME} #${env.BUILD_NUMBER} has failured"
        }
        success {
            echo "The build ${env.JOB_NAME} #${env.BUILD_NUMBER} has successfully been built"
        }
    }
}

pipeline and agent derivatives are specific to Declarative syntax. Overall declarative syntax aims to 'declare' the state of the pipeline.

Scripted Pipelines

The scripted pipelines examples have suffix *-scripted.groovy appended on to the file.

Scripted pipelines were the originally Jenkins pipeline syntax from the beginning of Jenkins 2.0+.

They are same as Declarative pipelines except that:

  • they don't follow a rigid structure
  • they don't have many constructs which many of them are actually specific to declarative syntax
  • they can contain groovy code directly as it is basically based on groovy's dsl.
  • due to its flexible nature (using groovy DSL to do logic etc...) it is more imperative than declarative syntax
  • they encompass a node block e.g.
node {
    stage("Source") {
        git credentialsId: "github_credentials", url: "https://github.com/colinbut/jenkins-pipelines.git"
    }

    def maven = tool 'apache-maven-3.6.3'

    stage("Compile") {
        sh "${maven}/bin/mvn clean compile"
    }
    stage("Unit Tests") {
        sh "${maven}/bin/mvn test"
    }
    stage("Integration Tests") {
        sh "${maven}/bin/mvn verify"
    }
    stage("Package") {
        sh "${maven}/bin/mvn package -DskipTests=true"
    }
}

Shared Library Examples

For the examples that uses a Shared Library, this project has close dependency on the Jenkins Shared Library side project (another personal project of mines).

e.g.

@Library("my-shared-library") _

buildJavaAppDockerFull(repo: "jenkins-pipelines", microserviceName: "example-app")

The above (taken from 013-java-app-docker-full-pipeline-shared-library.groovy) loads in an already configured Jenkins Shared Library in Jenkins Configure System.

jenkins-pipelines's People

Contributors

colinbut avatar

Watchers

James Cloos 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.