kubernetesjenkinscontainerskubernetes-helmjcasc

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


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?


Solution

  • 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'
          }
        }
      }
    }