22179?1514084564

【缺陷】 pipeline并行执行示例 正常


王威添加于 2017-04-25 21:30
// 脚本段1
def stepsForParallel = [:]

stepsForParallel['a'] = { 
    node () {
        echo 'a'
    }
}

stepsForParallel['b'] = { 
    node () {
        echo 'b'
    }
}

parallel stepsForParallel




// 脚本段2
// While you can't use Groovy's .collect or similar methods currently, you can
// still transform a list into a set of actual build steps to be executed in
// parallel.

// Our initial list of strings we want to echo in parallel
def stringsToEcho = ["a", "b", "c", "d"]

// The map we'll store the parallel steps in before executing them.
def stepsForParallel = [:]

// The standard 'for (String s: stringsToEcho)' syntax also doesn't work, so we
// need to use old school 'for (int i = 0...)' style for loops.
for (int i = 0; i < stringsToEcho.size(); i++) {
    // Get the actual string here.
    def s = stringsToEcho.get(i)

    // Transform that into a step and add the step to the map as the value, with
    // a name for the parallel step as the key. Here, we'll just use something
    // like "echoing (string)"
    def stepName = "echoing ${s}"
    
    stepsForParallel[stepName] = transformIntoStep(s)
}

// Actually run the steps in parallel - parallel takes a map as an argument,
// hence the above.
parallel stepsForParallel

// Take the string and echo it.
def transformIntoStep(inputString) {
    // We need to wrap what we return in a Groovy closure, or else it's invoked
    // when this method is called, not when we pass it to parallel.
    // To do this, you need to wrap the code below in { }, and either return
    // that explicitly, or use { -> } syntax.
    return {
        node {
            echo inputString
        }
    }
}
回复(1)
  • 22179?1514084564
    王威 8年前

    描述 已更新。 (查看差别)

0?1470885445
登录后可添加回复
  • 当前状态 新增
  • 选定优先级 正常
  • 指派给 --
  • 里程碑 --
  • 开始日期 2017-04-25
  • 结束日期
  • 预计工时(H) 0.00 小时
  • 完成度 0%
  • 关联Commit

© Copyright 2007~2021 国防科技大学Trustie团队 & IntelliDE 湘ICP备 17009477号

问题和建议
还能输入50个字符 提交

加入QQ群

关注微信APP


×