Py学习  »  docker

在声明性pipleine中如何在docker代理和“常规”代理之间动态切换

Clayton Keleher • 7 年前 • 2677 次点击  

我有一个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 . 这有可能吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38965
文章 [ 1 ]  |  最新文章 7 年前