How to reuse pod across job executions without the deprecated "label" option

We used to have jobs defined like follow to reuse pods across job executions:

pipeline {
  agent {
    kubernetes {
      cloud 'kubernetes'
      idleMinutes 10
      label "testjob"
      defaultContainer 'fedora'
      yaml '''
        spec:
          containers:
          - name: fedora
            image: 'registry.fedoraproject.org/fedora-minimal:latest'
            command: [ 'sleep', 'infinity' ]
      '''
    }
  }

  stages {
    stage("Run Test") {
      steps {
        sh 'echo yes'
      }
    }
  }
}

With both idleMinutes and label are present, the job can be executed in the same pod without booting up a new one, the reason for us to execute the job on same pod is our job can be triggered very frequently, booting up a new pod for each build can be time and resource consuming and almost unacceptable for us.

Now I see there is a message says:

[WARNING] label option is deprecated. To use a static pod template, use the 'inheritFrom' option.

However I don’t find a solution to achieve the same goal without the “label” option, could someone help on how I can do that without the deprecated label option?

1 Like

I’m currently looking into the same issue.

Seems as if the only option to retain that behavior is:

  1. Create a global template with your label in the Kubernetes cloud config
  2. Inherit in your pipeline from that label

You could create a global template with some label, and use it with agent label (instead kubernetes agent).