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