Radiant
Radiant

Reputation: 390

node is not a kubernetes node

I am trying to run simple jenkins pipeline for Maven project. When I try to run it on Jenkins, I am getting below error:

ERROR: Node is not a Kubernetes node:

I have searched everything related to this error but could not find anything.

Can someone tell me where am I doing mistake?

Jenkinsfile:

pipeline {
    agent {
        kubernetes {
            cloud 'openshift'
            label 'test'
            yamlFile 'jenkins/BuildPod.yaml'
        }
    }
    stages {
        stage('Build stage') {
            steps {
                sh 'mvn -B clean verify'
            }
        }
        stage('Test stage') {
            steps {
                sh 'mvn test'
            }
        }
        stage('Package stage') {
            steps {
                sh 'mvn package'
            }
        }
    }
}

BuildPod.yaml:

kind: Pod
apiVersion: v1
metadata:
  name: test
  labels:
    app: test
spec:
  containers:
    - name: jnlp
      image: openshift/jenkins-slave-base-centos7:latest
      envFrom:
        - configMapRef:
            name: jenkins-config
    - name: oc-dev
      image: reliefmelone/ocalpine-os:latest
      tty: true
      command:
        - cat
    - name: maven
      image: maven:3.6.1-jdk-13
      tty: true
      command:
        - cat
    - name: jdk
      image: 13-jdk-alpine
      tty: true
      command:
        - cat

I just want to build my project now. But it is not working.

Upvotes: 5

Views: 6028

Answers (1)

Freddie Fabregas
Freddie Fabregas

Reputation: 1203

You're missing the container in your stage step.

Example:

stage('Build stage') {
        steps {
            container('maven') {
                sh 'mvn -B clean verify'
            }
        }
    }

Upvotes: 2

Related Questions