Giter Site home page Giter Site logo

cico-pipeline-library's Introduction

CentOS CI Jenkins Pipeline Shared Libraries

Shared Library and example code to use Jenkinsfiles based Jenkins Pipelines in ci.centos.org

Pre-requisites

Usage of Shared Libraries

Option 1 - Global Configuration

Add global library 'cico-pipeline-library' pointing to github location https://github.com/CentOS/cico-pipeline-library
in (Manage Jenkins > Configure System > Global Pipeline Libraries) cico-pipeline-library-config Add @Library('cico-pipeline-library') _ into your Jenkinsfile pipeline file

Option 2 - Dynamically Load the Library

Add @Library('github.com/CentOS/cico-pipeline-library@master') _ into your Jenkins pipeline file to dynamically load the library.

Note: You can also specify a specify path for libraries insteaf of _ like import org.centos.*

More General Information:

  1. https://github.com/jenkinsci/workflow-cps-global-lib-plugin
  2. https://jenkins.io/doc/book/pipeline/shared-libraries/

Examples

Basic Library Example

vars/cicoPipeline.groovy

import org.centos.Utils

def call(body) {

    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

    def getDuffy = new Utils()
    def pipelineProps = ''
    try {
        def current_stage = 'cico-pipeline-lib-stage1'
        stage(current_stage) {
            writeFile file: "${env.WORKSPACE}/job.properties",
                    text: "MYVAR1=test\n" +
                          "MYVAR2=3\n"
        }
        current_stage = 'cico-pipeline-lib-stage2'
        stage(current_stage) {
            // Convert a classic shell properties file to groovy format to be loaded
            pipelineProps = convertProps("${env.WORKSPACE}/job.properties")
            // Load these as environment variables into the pipeline
            load(pipelineProps)
            sh '''
                echo "Original Shell Properties File:"
                cat ${WORKSPACE}/job.properties
                echo ""
                echo "Groovy Properties File:"
                cat ${WORKSPACE}/job.properties.groovy
                echo "Environment Variables"
                env
            '''
        }
    } catch (err) {
        echo "Error: Exception from " + current_stage + ":"
        echo err.getMessage()
        throw err
    }
}

Jenkinsfile

@Library('github.com/CentOS/cico-pipeline-library@master') _

node {
    deleteDir()
    cicoPipeline {}
}

cico-pipeline-library's People

Contributors

arilivigni avatar billrainford avatar bstinsonmhk avatar kbsingh avatar robnester-rh avatar scoheb avatar sergturi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cico-pipeline-library's Issues

We need a license

Let's pick a license for this library. We should probably do something like a BSD/Apache/MIT license or something similarly permissive.

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.