Skip to content

CentOS/cico-pipeline-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 {}
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages