Jenkins Kubernetes plugin interesting feature

Kubernetes plugin for Jenkins give us interesting ability to run multiple slaves as pods in the same time and execute commands on every of running slaves, moreover it can convert usual container into a slave. All you need is to define template like this:

  podContainers: [
    containerTemplate(
      name: 'jnlp',
      image: "${dockerRegistry}/cd/jenkins-slave-python",
      workingDir: '/tmp',
      alwaysPullImage: true,
      resourceRequestMemory: '1Gi',
      resourceLimitMemory: '2Gi',
      args: '${computer.jnlpmac} ${computer.name}'
    ),
    containerTemplate(
      name: 'python',
      image: 'python:3.8-slim',
      alwaysPullImage: true,
      ttyEnabled: true,
      resourceRequestMemory: '1Gi',
      resourceLimitMemory: '2Gi',
      command: '',
      workingDir: '/tmp'
    )
  ],

Please, pay attention to the second template definition. It has, from the first look, kind redundant specifications:

    command: '',
    workingDir: '/tmp'

However, Openshift places own scripts into /tmp folder and specification of this workdir is obligatory, in other case master won't be able to communicate with slave, and job will fail.

You can call slave in you pipeline with the next code:

 stage('Build') {
     sh 'oc get pods'
     sh """
           mkdir docker/dist
           cp -r src docker/dist
     """
     container('python') {
         stage('Build a Python project') {
            sh """
                  python --version &&
                  pip install numpy pandas matplotlib
               """
        }
    }
  }
More information: https://github.com/jenkinsci/kubernetes-plugin

Comments

Popular posts from this blog

Install Kubeflow locally

RabbitMQ and OpenShift