Jenkins slave as a kubernetes pod

946 views Asked by At

I have created kubernetes cluster in GCP and top of it i have configured jenkins in kubernetes using the below url https://cloud.google.com/solutions/jenkins-on-kubernetes-engine-tutorial

I am able to run jenkins build with normal commands and it is creating a pod and the build is getting successful. When i am trying to change the image for maven build or golang build, i am unable to complete it. When i try to change it the pod is keep on terminating and recreating.

jenkins kubernetes configuration

Jenkins pod template

Jenkins build

1

There are 1 answers

1
sai manikanta On

We can add pod template in Jenkins pipeline script to pull our custom image and to run as a slave pod. Use this below format:

pipeline {
  agent {
    kubernetes {
      defaultContainer 'jnlp'
      yaml """
apiVersion: v1
kind: Pod
metadata:
  labels:
    some-label: some-label-value
spec:
  containers:
  - name: maven
    image: maven:alpine
    command:
    - cat
    tty: true
  - name: busybox
    image: busybox
    command:
    - cat
    tty: true
"""
    }
  }
  stages {
    stage('Run maven') {
      steps {
        container('maven') {
          sh 'mvn -version'
        }
        container('busybox') {
          sh '/bin/busybox'
        }
      }
    }
  }
}