Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins 我如何有条件地创建代理;“对象”;管道?_Jenkins_Jenkins Pipeline_Jenkins Plugins - Fatal编程技术网

Jenkins 我如何有条件地创建代理;“对象”;管道?

Jenkins 我如何有条件地创建代理;“对象”;管道?,jenkins,jenkins-pipeline,jenkins-plugins,Jenkins,Jenkins Pipeline,Jenkins Plugins,我有一个管道,我想有条件地使用到不同类型的代理 我不想在管道级别设置默认值,因为这样每次都会设置该代理类型,即使不使用它 我有k8s奴隶和ECS奴隶,我基本上想这样做,但这不起作用: pipeline { agent { if (true) { kubernetes { defaultContainer "mycontainer" yaml 'my podspec'

我有一个管道,我想有条件地使用到不同类型的代理

我不想在管道级别设置默认值,因为这样每次都会设置该代理类型,即使不使用它

我有k8s奴隶和ECS奴隶,我基本上想这样做,但这不起作用:

pipeline {
    agent {
        if (true) {
            kubernetes {
                defaultContainer "mycontainer"
                yaml 'my podspec'
            }
        } else {
            node {
                label 'my-ecs-cluster'
                customWorkspace 'myworkspace'
            }
        }
    }

希望下面的示例管道脚本可以帮助您解决问题

pipeline
{
    agent none
    parameters
    {
        choice(name: 'agent', choices: ['master','slave'], description: 'Agent Selection!')
    }
    stages
    {
        stage('Say Hello - Master')
        {
            when
            {
                expression
                {
                    agent == 'master' 
                }
            }
            agent
            {
                node
                {
                    label 'master'
                }
            }
            steps
            {
                echo 'hello master'
            }
        }
         stage('Say Hello - Slave')
        {
            when
            {
                expression
                {
                    agent == 'slave' 
                }
            }
            agent
            {
                node
                {
                    label 'slave'
                }
            }
            steps
            {
                echo 'hello slave'
            }
        }
    }
}
希望这能有所帮助