Jenkins Kubernetes (JCASC) How to set default container to my container instead of JNLP?

1.4k Views Asked by At

I'm using pipelines in Jenkins that are running using JNLP container instead of my container.

I'm using Jenkins as a code (Jenkin Helm chart)

If I add this block to the pipeline -

 container('my container') {
}

It is using 'my container'.

How do I set it as default to all my pipelines? Do I really need to add this container block all the time?

2

There are 2 best solutions below

2
Michał Lewndowski On BEST ANSWER

As mentioned in kubernetes plugin doc you can change it globally with following code:

pipeline {
  agent {
    kubernetes {
      defaultContainer 'maven'
      yamlFile 'KubernetesPod.yaml'
    }
  }

  stages {
    stage('Run maven') {
      steps {
        sh 'mvn -version'
      }
    }
  }
}
0
Sai Chandra Gadde On

As per this issue to define a different default jnlp container follow below steps:

  1. Go to Configure clouds page -> Kubernetes -> Click on Kubernetes Cloud details ... -> Click Advanced -> Default Provider Template Name.

  2. Use the same name in the Pod Template -> name field.

  3. Then set the desired jnlp container template image.

Attaching another blog for your reference.