zoukankan      html  css  js  c++  java
  • jenkins2 Jenkinsfile和load

    更复杂的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

  • 相关阅读:
    CodeForces 620D Professor GukiZ and Two Arrays 双指针
    模板汇总 —— 最大团
    CodeForces 1105E Helping Hiasat 最大独立集
    CodeForces 925 C Big Secret
    CodeForces 979 D Kuro and GCD and XOR and SUM
    CodeForces 665E Beautiful Subarrays 字典树
    CodeForces 723F st-Spanning Tree
    CodeForces 103D Time to Raid Cowavans 询问分块
    博客园添加访问次数统计
    oracle转mysql总结
  • 原文地址:https://www.cnblogs.com/itech/p/5660628.html
Copyright © 2011-2022 走看看