Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Plugin- Declarative Pipeline -ERROR: Node is not a Kubernetes node:

The declarative pipeline by defining yaml inside the kuberentes section of agent is not working. I was using jenkins 2.176.x LTS version. I am getting the following error in the console "ERROR: Node is not a Kubernetes node:" error.jpg I have tried all the existing solutions available in stack overflow.

Please find the pipeline code:

        pipeline {
            agent {
             kubernetes {
              //cloud 'kubernetes'
              yaml """
                apiVersion: v1
               kind: Pod
        spec:
          containers:
          - name: maven
            image: maven:3.3.9-jdk-8-alpine
            command: ['cat']
            tty: true
        """
            }
          }
          stages {
            stage('Run maven') {
              steps {
                container('maven') {
                  sh 'mvn -version'
                }
              }
            }
          }
        }

It should deploy the pod and run the command

like image 622
KiranKumar G Avatar asked Feb 06 '26 10:02

KiranKumar G


1 Answers

You must supply a label to the kubernetes block:

kubernetes {
  label 'mylabel'
  yaml """
  ....
}
like image 116
Cliffred Avatar answered Feb 15 '26 22:02

Cliffred



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!