Search code examples
shelljenkins-pipelinekubernetes-helm

Nullpointer exception after running kubectl and helm command in Jenkinsfile


I am trying to run kubernetes and helm command in the deploy step of the Jenkinsfile but I am facing Nullpointer exception. Below is my code:

stage ('Create and Deploy to k8s Dev Environment') {
            //agent {label 'docker-maven-slave'}
            options {
                skipDefaultCheckout()
            }
            steps {
                withCredentials([string(credentialsId: K8S_DEV_SECRET_ID)]) {
                    command """

                    kubectl apply --server=https://10.0.0.0:443 --insecure-skip-tls-verify=false --namespace: "dev-ns" -f -

                    helm template -f "portal-chart/deploy/values-dev.yaml" portal-chart
                    """
                }
}

Below are the logs:

[Pipeline] End of Pipeline
hudson.remoting.ProxyException: java.lang.NullPointerException
Caused: hudson.remoting.ProxyException: com.xxx.jenkins.pipeline.library.utils.dispatch.ShellCommandException: Exception calling shell command, 'kubectl apply ... ': null
    at command.call(command.groovy:51)

Solution

  • I was able to resolve this. Below is the code:

    stage ('Create and Deploy to k8s Dev Environment') {
                //agent {label 'docker-maven-slave'}
                options {
                    skipDefaultCheckout()
                }
                steps {
                        command """
    
                        kubectl apply --server=https://10.0.0.0:443 --insecure-skip-tls-verify=false --namespace: "dev-ns" -f -
    
                        helm template -f "portal-chart/deploy/values-dev.yaml" portal-chart
                        """
                    
    }