Jenkins下的Pipeline流水线入门篇

持续更新中(2018年7月20日)

引用文章地址:

一、安装Jenkins集成部署服务,选择推荐安装服务插件。

二、安装pipeline插件,Git插件,Gitlab插件。

三、Pipeline语法篇

1.1   pipeline脚本

  1. Pipeline最基本的部分是“step”。基本上,step告诉Jenkins 要做什么,并且作为Declarative Pipeline和Scripted Pipeline语法的基本构建块。
  2. Pipeline支持两种语法:Declarative Pipeline(在Pipeline 2.5中引入,结构化方式)和Scripted Pipeline,两者都支持建立连续输送的Pipeline。
  3. 为与BlueOcean脚本编辑器兼容,通常建议使用Declarative Pipeline的方式进行编写。

2.1   Declarative Pipeline明式 (主要使用方式)

所有有效的Declarative Pipeline必须包含在一个pipeline块内,例如:

pipeline {

/* insert Declarative Pipeline here */

 }

Declarative Pipeline中的基本语句和表达式遵循与Groovy语法相同的规则 ,但有以下例外:

1Pipeline的顶层必须是块,具体来说是:pipeline { }

2.没有分号作为语句分隔符。每个声明必须在自己的一行

3.块只能包含Sections, Directives, Steps或赋值语句。

4.属性引用语句被视为无参方法调用。所以例如,输入被视为input()

3.1 示例

  1.基本pipeline构建

  

pipeline {
    agent any
    environment { 
    def ITEMNAME = "SpringMVC"
    def SRCCODE_DIR = "/root/.jenkins/workspace/Test-Pipeline/"
    def PATHS = pwd()
    def PM = "/root/.jenkins/workspace/Test-Pipeline/target"
    }
    stages {
        stage('代码拉取并打包'){
            steps {
            echo "checkout from ${ITEMNAME} to ${SRCCODE_DIR}"
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '63b8acaa-b26f-42ff-80dc-e70937133e3a', url: '[email protected]:root/easy.git']]])
            echo "maven build war package"
            sh 'export JAVA_HOME=/usr/java/default && cd $SRCCODE_DIR && mvn clean install -DskipTests -Denv=beta'    
            }
    }
    }
}

  2.

猜你喜欢

转载自www.cnblogs.com/thinksep/p/9340877.html