更复杂的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. sin, miss the mark, correct our aim and try again

    Guilt should only be a call to action. When we see that we "missed the mark"(the meaning o ...

  2. Win7 64位系统 VS2010连接Oracle报错的问题

    1,异常现象: TNS无法识别 2,异常分析:VS2010启动调试的时候,出现异常.但是使用IIS作为服务器的时候,是不会出现异常,也就是可以正常访问到数据库,后来分析是由于VS自带服务器ASP.NE ...

  3. C语课设心得分享(二)

    咱们今儿说说IDE的事儿. IDE是「集成开发环境」的意思,比如咱们常用的VC6.0,就是开发C语言所用的IDE的一种.对于IDE的认识,可能有些朋友有点儿模糊,咱们捋一捋,我也会给出一些IDE方面的 ...

  4. 将CSDN和WordPress上的旧文章迁移过来

    我最早用的博客是CSDN,但是不喜欢CSDN的博客,发文章还要审核,界面做的也很模糊,发个文章还必须选个分类.总之不像是用心在做博客这个功能. 后来,我自己搭建了一个网站(www.wangyufeng ...

  5. linux Bash

    本文包含的命令:type.echo.evn.set.locale.read.declare / typeset.ulimit.alias.unalias.history.!.source.stty.c ...

  6. JS向光标指定位置插入内容

    方法: function insertHtmlAtCaret(html) { var sel, range; if (window.getSelection) { // IE9 and non-IE ...

  7. "2013":爱你不容易

    2013对我来说确实像年初时曾给自己定义的那样,真的是非常不平常的一年.依稀记得去年年终时,BOSS和我深聊了1多钟头,谈到职业规划.人生还有家庭的林林种种.春节在家时也仔细考虑过2013自己该如何规 ...

  8. FreeBSD_11-系统管理——{Part_2-核心}

    一.Managing Services in FreeBSD Service restart will only work if it is set to YES in /etc/rc.conf. T ...

  9. Oracle列操作(增加列,修改列,删除列)

    Oracle列操作 增加一列: alter table emp4 add test varchar2(10); 修改一列: alter table emp4 modify test varchar2( ...

  10. 更换光纤后路由器端口映射 -VPN相关

    之前一直是ADSL的线路,使用路由器后,很简单就可以实现端口映射了!外网也可以随意连接,可是最近升级宽带更换了光纤后,发现怎么都不能正常工作了!在光纤猫里显示的IP居然是:10.0.*.*,查询到的外 ...