jenkins kubernetes-plugin set idletimeout in pipeline

8/16/2017

How to set Time in minutes to retain slave when idle and Max number of instances in pipeline when config podTemplate ?

I see these two config options in System->Could->kubernetes. But I use pipeline and I didn't figure it out how to set them.

Now My pipeline looks like below.

podTemplate(label: 'docker-go',
  containers: [
        containerTemplate(
            name: 'jnlp',
            image: 'docker.mydomain.com/library/jnlp-slave:2.62',
            command: '',
            args: '${computer.jnlpmac} ${computer.name}',
        ),
        containerTemplate(name: 'docker', image: 'docker.mydomain.com/library/docker:1.12.6', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'golang', image: 'docker.mydomain.com/library/golang:1.8.3', ttyEnabled: true, command: '')
  ],
  volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')]
  ) {

  def image_tag = "docker.mydomain.com/deploy-demo/demo-go:v0.1"
  def workdir = "/go/src/demo-go"
  node('docker-go') {
    stage('setup') {

    }

    stage('clone') {
    }
    stage('compile') {

    }
    stage('build and push image') {
    }
  }
}
-- xren
jenkins
jenkins-pipeline
jenkins-plugins
kubernetes

1 Answer

8/16/2017

Ok, I figuire it out

Add these two. idleMinutes: 10 instanceCap: 10

podTemplate(label: 'docker-go',
  containers: [
        containerTemplate(
            name: 'jnlp',
            image: 'docker.mydomain.com/library/jnlp-slave:2.62',
            command: '',
            args: '${computer.jnlpmac} ${computer.name}',
        ),
        containerTemplate(name: 'docker', image: 'docker.mydomain.com/library/docker:1.12.6', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'golang', image: 'docker.mydomain.com/library/golang:1.8.3', ttyEnabled: true, command: '')
  ],
  volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')],
  idleMinutes: 10
  instanceCap: 10
  ) {

  def image_tag = "docker.mydomain.com/deploy-demo/demo-go:v0.1"
  def workdir = "/go/src/demo-go"
  node('docker-go') {
    stage('setup') {

    }

    stage('clone') {
    }
    stage('compile') {

    }
    stage('build and push image') {
    }
  }
}
-- xren
Source: StackOverflow