在声明性管道中在多个代理上并行运行相同的Jenkins作业
以下是我所拥有的:在声明性管道中在多个代理上并行运行相同的Jenkins作业,jenkins,groovy,jenkins-pipeline,Jenkins,Groovy,Jenkins Pipeline,以下是我所拥有的: #!/usr/bin/env groovy pipeline { agent none stages { stage('Checkout SCM') { agent { label 'win' && 'apple' && 'rhel' } steps { echo "Cloning Repository"
#!/usr/bin/env groovy
pipeline {
agent none
stages {
stage('Checkout SCM') {
agent { label 'win' && 'apple' && 'rhel' }
steps {
echo "Cloning Repository"
checkout([$class: 'GitSCM',
branches: [[name: "*/develop"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'WipeWorkspace']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'UNAME', url: 'URL']],
browser: [$class: 'BitbucketWeb', repoUrl: 'URL'],
])}}
stage('Building Win64, Linux764, MacOS') {
agent { label 'win&&rhel&&apple' }
steps {
script {
echo '************************'
echo '*****BUILDING JOBS******'
echo '************************'
sh 'python build.py'
sh 'cd ion-js && npm run prepublishOnly'
}}}
}
}
但是,我得到的没有标签为“win&&rhel&&apple”的节点错误。是否有人知道如何运行声明性jenkins管道,其中一个阶段在多个代理标签上并行运行
我想同时将相同的git repo签出到3个不同的节点。我试过agent{label'win&&'apple&&&rhel}
和agent{label'win&&apple&&rhel}
但它只是说找不到那个标签
|
和使用&&
应该可以,但我不确定我缺少了什么。我可以写3个不同的结帐阶段,但我认为有更好的方法,我尝试过同样的方法,但没有成功。我知道的唯一解决方案是为每个代理/节点/标签使用一个并行
块并多次定义阶段
stage('Building Win64, Linux764, MacOS') {
parallel {
stage('Win64') {
agent {
label 'win-10-x64'
}
steps {
...
}
}
stage('Linux64') {
agent {
label 'linux-x64'
}
steps {
...
}
}
stage('MacOS') {
agent {
label 'macos'
}
steps {
...
}
}
}
}
为了补充弥迦的答案,
您可以定义一个函数,该函数可以为您创建一个stage,并将在您选择的不同代理节点上执行generate stage,而不是使用不同的标签重复stage
def agents = ['win64', 'linux64', 'macos']
def generateStage(nodeLabel) {
return {
stage("Runs on ${nodeLabel}") {
node(nodeLabel) {
steps {
script {
echo "Running on ${nodeLabel}"
echo '************************'
echo '*****BUILDING JOBS******'
echo '************************'
sh 'python build.py'
sh 'cd ion-js && npm run prepublishOnly'
}
}
}
}
}
}
def parallelStagesMap = agents.collectEntries {
["${it}" : generateStage(it)]
}
pipeline {
agent none
stages {
stage('non-parallel stage') {
steps {
echo 'This stage will be executed first.'
}
}
stage('parallel stage') {
steps {
script {
parallel parallelStagesMap
}
}
}
}
}
因为我们在调用parallelStageMap时有parallel关键字,所以相同的阶段将在代理节点上并行执行
ProTip:您可以在函数中定义更多在所有代理上执行的步骤。
如果您想定义标签和阶段名称,可以添加另一个名为stagename
的参数,并可以解析为函数generateStage
我有一个类似的问题,您知道如何解决吗?