gpt4 book ai didi

Jenkinsfile 'parallel' 指令

转载 作者:行者123 更新时间:2023-12-04 02:01:28 28 4
gpt4 key购买 nike

我正在尝试写一个 Jenkinsfile并行执行一系列步骤。目标是拥有两个 agents (又名。 nodes )。一个应该进行 Windows 构建,另一个应该进行 linux 构建。但是,我不希望这种情况顺序发生,而是并行发生。我正在尝试查找 parallel 的文档Pipeline - Parallel execution of tasks 中描述的指令.

我发现了一次 parallel Jenkins 上的一个,但似乎文档已损坏:https://jenkins.io/doc/pipeline/steps/workflow-cps/

parallel: Execute in parallel

org.kohsuke.stapler.NoStaplerConstructorException:
There’s no @DataBoundConstructor on any constructor of class
org.jenkinsci.plugins.workflow.cps.steps.ParallelStep

我应该如何设置一个可以在两个不同的代理(一个 linux,一个 Windows)上并行执行一系列构建步骤的 Jenkinsfile?

特别是,我应该使用声明式还是基于脚本的管道 DSL?

最佳答案

您可以使用声明式或基于脚本的来进行并行工作。可以在此处找到基于脚本的并行文档:https://jenkins.io/doc/book/pipeline/jenkinsfile/#advanced-scripted-pipeline

他们给出了以下示例...

stage('Build') {
/* .. snip .. */
}

stage('Test') {
parallel linux: {
node('linux') {
checkout scm
try {
unstash 'app'
sh 'make check'
}
finally {
junit '**/target/*.xml'
}
}
},
windows: {
node('windows') {
/* .. snip .. */
}
}
}

对于声明,我相信你会这样做:

stage('Build') {
steps {
parallel (
"Windows" : {
echo 'done'
},
"Linux" : {
echo 'done'
}
)
}
}

声明式管道 1.2 ,首选的声明性语法是:

pipeline {
agent none
stages {
stage('Run Tests') {
parallel {
stage('Test On Windows') {
agent {
label "windows"
}
steps {
bat "run-tests.bat"
}
post {
always {
junit "**/TEST-*.xml"
}
}
}
stage('Test On Linux') {
agent {
label "linux"
}
steps {
sh "run-tests.sh"
}
post {
always {
junit "**/TEST-*.xml"
}
}
}
}
}
}
}

关于Jenkinsfile 'parallel' 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43913698/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com