Dynamic agent type selection based on parameter

I would like to implement in jenkins pipeline method to select agent type like
docker, dockerfile, kubernetes, label, none
in the nutshell

if ( $TESTS == “Bitbucket”) {
agent {
kubernetes { yamlFile ‘rc/config/default/node-template.yaml’ // separate yaml file defining the pod template
defaultContainer ‘python’ // the default container where all task will be exceuted, unless other specified
else {
agent none

Is it possible ???
Please drop me any hints ?

You cannot do this in Declarative syntax but it should be straightforward in Scripted syntax.


You helped me a lot !!!

1 Like