我有一个Jenkinsfile,它有时需要在一个节点上运行,有时需要在Docker代理上运行,这取决于某些参数。我希望让Jenkins管道在使用Docker代理声明和更普通的代理声明之间进行动态切换。我唯一缺少的是如何参数化代理声明。我尝试简单地从通过变量传递代理声明开始,到目前为止我有:
def agentDeclaration = {
docker {
label '...'
image "..."
args "..."
}
}
...
pipeline {
agent agentDeclaration
...
}
但失败的原因是:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 117: Only "agent none", "agent any" or "agent {...}" are allowed. @ line 117, column 13.
agent agentDeclaration
^
WorkflowScript: 117: No agent type specified. Must be one of [any, docker, dockerfile, kubernetes, label, none] @ line 117, column 13.
agent agentDeclaration
我看到以前也问过类似的问题
here
和
here
. 这有可能吗?