更复杂的pipeline实例,使用了Jenkinsfile和load。

文章来自:http://www.ciandcd.com
文中的代码来自可以从github下载: https://github.com/ciandcd
 
实例代码来自:https://github.com/jenkinsci/workflow-aggregator-plugin/tree/master/demo/repo
 
1. groovy脚本
https://github.com/jenkinsci/workflow-aggregator-plugin/blob/master/demo/repo/servers.groovy

def deploy(id) {
unstash 'war'
sh "cp x.war /tmp/webapps/${id}.war"
}

def undeploy(id) {
sh "rm /tmp/webapps/${id}.war"
}

def runWithServer(body) {
def id = UUID.randomUUID().toString()
deploy id
try {
body.call id
} finally {
undeploy id
}
}

this

2. Jenkinsfile

https://github.com/jenkinsci/workflow-aggregator-plugin/blob/master/demo/repo/Jenkinsfile

jettyUrl = 'http://localhost:8081/'

def servers

stage 'Dev'
node {
checkout scm
servers = load 'servers.groovy'
mvn '-o clean package'
dir('target') {stash name: 'war', includes: 'x.war'}
}

stage 'QA'
parallel(longerTests: {
runTests(servers, 30)
}, quickerTests: {
runTests(servers, 20)
})

stage name: 'Staging', concurrency: 1
node {
servers.deploy 'staging'
}

input message: "Does ${jettyUrl}staging/ look good?"
try {
checkpoint('Before production')
} catch (NoSuchMethodError _) {
echo 'Checkpoint feature available in CloudBees Jenkins Enterprise.'
}

stage name: 'Production', concurrency: 1
node {
sh "wget -O - -S ${jettyUrl}staging/"
echo 'Production server looks to be alive'
servers.deploy 'production'
echo "Deployed to ${jettyUrl}production/"
}

def mvn(args) {
sh "${tool 'Maven 3.x'}/bin/mvn ${args}"
}

def runTests(servers, duration) {
node {
checkout scm
servers.runWithServer {id ->
mvn "-o -f sometests test -Durl=${jettyUrl}${id}/ -Dduration=${duration}"
}
}
}

3. 如果有兴趣可以下载pipeline demo docker image

https://github.com/jenkinsci/workflow-aggregator-plugin/tree/master/demo

jenkins2 Jenkinsfile和load的更多相关文章

  1. jenkins2 Jenkinsfile

    推荐使用Jenkinsfile代替将groovy脚本直接写在jenkins job里. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://g ...

  2. Jenkins pipeline 入门到精通系列文章

    Jenkins2 入门到精通系列文章. Jenkins2 下载与启动jenkins2 插件安装jenkins2 hellopipelinejenkins2 pipeline介绍jenkins2 jav ...

  3. Jenkins2.0中的pipeline

    jenkins的实现是标准的master/slave模式,用户与master交互,master将job分布到slave上运行. jenkins的基本概念: 1. master, 也就是jenkins的 ...

  4. centos7.6环境jenkins升级到tomcat8.0.53和jenkins2.168版本

    Jenkins服务器:192.168.10.175数据备份服务器:192.168.10.164 jenkins服务器报错不能访问,插件无法加载就不能正常获取代码,重启尝试解决无果,于是采用 如下方案: ...

  5. Centos 下 Jenkins2.6 + Git + Maven Shell一件部署与备份

    使用Jenkins2.6 集成Maven与Git插件做持续集成,同时编写Shell脚本备份与发布(需要稍微知道点Linux/毕竟基于Centos PS:本人Linux也是菜鸡) - 下载Jenkins ...

  6. load和initialize方法

      一.load 方法什么时候调用: 在main方法还没执行的时候 就会 加载所有类,调用所有类的load方法. load方法是线程安全的,它使用了锁,我们应该避免线程阻塞在load方法. 在项目中使 ...

  7. "NHibernate.Exceptions.GenericADOException: could not load an entity" 解决方案

     今天,测试一个项目的时候,抛出了这个莫名其妙的异常,然后就开始了一天的调试之旅... 花了很长时间,没有从代码找出任何问题... 那么到底哪里出问题呢? 根据下面那段长长的错误日志: -- ::, ...

  8. hibernate的get和load的区别

    在hibernate中我们知道如果要从数据库中得到一个对象,通常有两种方式,一种是通过session.get()方法,另一种就是通过session.load()方法,然后其实这两种方法在获得一个实体对 ...

  9. DOM加载过程中ready和load的区别

    在浏览器地址栏输入URL地址,浏览器开始加载页面时,有以下几个过程 1.浏览器开始解析HTML文档 2. 浏览器遇到HTML文档中的<script>元素以及CSS样式文件,并且没有asyn ...

随机推荐

  1. LESS与SASS的伯与仲

    工作中用到了Bootstrap,涉及到了LESS,对其做了一个简单的了解,CSS的预处理器使用最广泛的就是LESS和Sass,都是努力把CSS武装成为开发语言,让它从简单的描述性语言过渡到具有程序式特 ...

  2. [转]libsvm 训练后的模型参数讲解

    http://blog.sina.com.cn/s/blog_6646924501018fqc.html 主要就是讲解利用libsvm-mat工具箱建立分类(回归模型)后,得到的模型model里面参数 ...

  3. [python] import curses

    python 中,我们使用 curses.wrapper 来创建终端交互window.使用 stdscr 来代表 window 对象. 使用方法: from curses import wrapper ...

  4. POJ 1873 - The Fortified Forest 凸包 + 搜索 模板

    通过这道题发现了原来写凸包的一些不注意之处和一些错误..有些错误很要命.. 这题 N = 15 1 << 15 = 32768 直接枚举完全可行 卡在异常情况判断上很久,只有 顶点数 &g ...

  5. iOS 设置button文字过长而显示省略号的解决办法

    UIButton * button =[UIButton buttonWithType:UIButtonTypeCustom];button.titleLabel.adjustsFontSizeToF ...

  6. iconv命令 gbk 转 UTF-8

    -----linux gbk 转 UTF-8-------- iconv 用法 iconv -f "gbk" -t "utf-8" < infile &g ...

  7. hdu 5791 (DP) Two

    hdu 5791 Two Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. 真正意义上的spring环境中的单元测试方案spring-test与mokito完美结合

    真正意义上的spring环境中的单元测试方案spring-test与mokito完美结合 博客分类: java 测试 单元测试SpringCC++C#  一.要解决的问题:     spring环境中 ...

  9. jquery 获取radio选中的值

    如下案例:常用方法 1.获取选中值,三种方法都可以: $('input:radio:checked').val(): $("input[type='radio']:checked" ...

  10. php执行流程

    1.源码文件编写,php源文件 2.词法分析,token 3.语法分析,生成opcode并组成opcode array 4.执行opcode,返回结果