詹金斯 - >循环槽Docker-Agent
我想在 jenkins-pipeline中使用几个 docker-images 构建一些软件包 。下面的管道有效..但是我想实现阶段是一个更“循环”的方式。...
pipeline {
agent { label 'docker' }
stages {
stage ('Running on ubuntu:20.04') {
agent {
docker {
reuseNode true
label 'docker'
image 'ubuntu:20.04'
}
}
steps {
sh 'uname -a && bash --version'
}
}
stage ('Running on ubuntu:22.04') {
agent {
docker {
reuseNode true
label 'docker'
image 'ubuntu:22.04'
}
}
steps {
sh 'uname -a && bash --version'
}
}
}
}
一个想法如何实施? ..
最初,我尝试使用这样的东西
pipeline {
agent { label 'docker' }
stages {
stage ('Loop-Stage') {
steps {
script {
// Loop trough List (*works*)
for (item in ['ubuntu:20.04', 'ubuntu:22.04']) {
// Create new stage (*works*)
stage ('Running on ${item}') {
// Set agent (*fails*)
agent {
docker {
reuseNode true
label 'docker'
image "${item}"
}
}
steps {
sh 'uname -a && bash --version'
}
}
}
}
}
}
}
}
,但现在确实有效。该错误似乎表明脚本化和声明语法之间的混合物。您会收到以下错误:
java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, addInteractivePromotion, ansiColor, archive, artifactoryBuildTrigger, artifactoryDistributeBuild, artifactoryDownload, artifactoryEditProps, artifactoryGoPublish, ar
如何将相应的“代理”应用于动态生成的阶段?
I want to build some Packages using several Docker-Images in a Jenkins-Pipeline
. The Pipeline below works .. but I want to implement the Stage(s) is a more "Loop"-ish way ....
pipeline {
agent { label 'docker' }
stages {
stage ('Running on ubuntu:20.04') {
agent {
docker {
reuseNode true
label 'docker'
image 'ubuntu:20.04'
}
}
steps {
sh 'uname -a && bash --version'
}
}
stage ('Running on ubuntu:22.04') {
agent {
docker {
reuseNode true
label 'docker'
image 'ubuntu:22.04'
}
}
steps {
sh 'uname -a && bash --version'
}
}
}
}
An Ideas how to implement that ? ..
Initially I tried using something like this
pipeline {
agent { label 'docker' }
stages {
stage ('Loop-Stage') {
steps {
script {
// Loop trough List (*works*)
for (item in ['ubuntu:20.04', 'ubuntu:22.04']) {
// Create new stage (*works*)
stage ('Running on ${item}') {
// Set agent (*fails*)
agent {
docker {
reuseNode true
label 'docker'
image "${item}"
}
}
steps {
sh 'uname -a && bash --version'
}
}
}
}
}
}
}
}
But this does now work. The Error seems to indicate a mixture between scripted&declarative Syntax .. you get the following error:
java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, addInteractivePromotion, ansiColor, archive, artifactoryBuildTrigger, artifactoryDistributeBuild, artifactoryDownload, artifactoryEditProps, artifactoryGoPublish, ar
How can I apply a the corresponding "agent" to the dynamically generated Stage ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您进入脚本块时,您无法再使用一些声明语法,例如
agent
。这就是为什么您会收到错误java.lang.lang.nosuchmethoderror:没有这样的DSL方法'agent'
。詹金斯(Jenkins)对您是否正在尝试使用声明的管道语法或仅使用Groovy的脚本语法感到困惑。您可以做这样的事情。这将创建一个阶段列表,然后并行执行。
如果需要顺序执行,则可以修改管道,如下所示。
When you go into a script block you can no longer use some of the declarative syntaxes like
agent
. That's why you are getting the errorjava.lang.NoSuchMethodError: No such DSL method 'agent'
. Jenkins is confused about whether you are trying to use Declarative Pipeline syntax or just scripted syntax with groovy.You can do something like this. This will create a list of stages and then execute them in parallel.
If you want sequential execution, you can modify your pipeline as shown below.