Skip to content

Instantly share code, notes, and snippets.

@iguoli
Created September 17, 2018 02:09
Show Gist options
  • Save iguoli/9d17076bce12f2f72f02d538c0929d1e to your computer and use it in GitHub Desktop.
Save iguoli/9d17076bce12f2f72f02d538c0929d1e to your computer and use it in GitHub Desktop.
Pipeline Example

Jenkins Pipeline 简介

Jenkins Pipeline (or simply "Pipeline") provides an extensible set of tools for modeling simple-to-complex delivery pipelines "as code". The definition of a Jenkins Pipeline is typically written into a text file (called a Jenkinsfile) which in turn is checked into a project’s source control repository.

Pipeline 定义

  • Declarative Pipeline
  • Scripted Pipeline (a limited form of Groovy)

Both are DSLs to describe portions of your software delivery pipeline.

Pipeline 可以使用下面三种方法创建:

  • Through Blue Ocean
  • Through the classic UI
  • In SCM

Jenkinsfile

Jenkinsfile (Declarative Pipeline)

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building..'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying....'
            }
        }
    }

    post {
        always {
            junit '**/target/*.xml'
        }
        failure {
            mail to: team@example.com, subject: 'The Pipeline failed :('
        }
    }
}

全局变量

The Global Variable Reference only contains documentation for variables provided by Pipeline or plugins.

http://localhost:8080/pipeline-syntax/globals

env

Environment variables can be set globally or per stage. Setting environment variables per stage means they will only apply to the stage in which they’re defined.

env.PATH

pipeline {
    agent any

    environment {
        COOKBOOK = 'propel_ha'
    }

    stages {
        stage('Build') {
            environment {
                DEPLOY_UI = 'yes'
            }
            steps {
                echo "Global Environment Variable COOKBOOK = $env.COOKBOOK"
                echo "Stage Environment Variable DEPLOY_UI = $env.DEPLOY_UI"

                sh 'env'
            }
        }
    }
}

params

params.sap_adapter_gitsha

currentBuild

currentBuild.result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment