##什么是jenkins 请参看这个连接java
pipeline就是一套运行于jenkins之上的工做流框架,将本来独立运行于单个或者多个节点的任务链接起来,实现单个任务难以完成的复杂发布流程,pipeline的实现方式是一套groovy DSL,任何发布流程均可以表述为一段groovy脚本,而且jenkins支持从代码库直接读取脚本,从而实现pipeline as code的理念。node
##pipeline功能:linux
##pipeline的基本概念git
stage是一个逻辑分组的概念,是能够跨多个node的
。##熟悉jenkins的术语github
##pipeline对jenkins版本的要求docker
##安装pipeline插件及其周边插件windows
##pipeline with SCMbash
##jenkins的docker demo 能够用docker安装一个docker版的jenkins,这是连接地址框架
##建立一个pipelinemaven
node { echo 'Hello from Pipeline' }
Started by user anonymous [Pipeline] echo Hello from Pipeline [Pipeline] End of Pipeline Finished: SUCCESS
##并行执行
parallel 'integration-tests':{ node('mvn-3.3'){} }, 'functional-tests':{ node('selenium'){} }
##使用片断生成器
##添加tools
node { git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git' def mvnHome = tool 'M3' sh "${mvnHome}/bin/mvn -B verify" }
注意
:sh是在linux或类unix系统上,而在windows上表示为
bat "${mvnHome}\\bin\\mvn -B verify"
##一个java环境下的Maven自动化构建流程
##groovy语法的pipeline配置
git([url: 'https://github.com/joe_user/simple-maven-project-with-tests.git', branch: 'master'])
通常的,在step只有一个参数时,你能够省略参数的名称,如:
sh 'echo hello'
其原意为
sh([script: 'echo hello'])
##管理环境变量
node { git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git' def mvnHome = tool 'M3' env.PATH = "${mvnHome}/bin:${env.PATH}" sh 'mvn -B verify' }
mvn
就不须要完整的路径。##也能够添加为一个局部的环境变量
node { git url: 'https://github.com/jglick/simple-maven-project-with-tests.git' withEnv(["PATH+MAVEN=${tool 'M3'}/bin"]) { sh 'mvn -B verify' } }
##收集测试结果
node { git 'https://github.com/joe_user/simple-maven-project-with-tests.git' def mvnHome = tool 'M3' sh "${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore verify" archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true junit '**/target/surefire-reports/TEST-*.xml' }
##pipeline一些具体的实例 请参考这个连接jenkins pipeline example