<p>Summary: is there a Jenkins plugin that allows to deploy stateful applications?</p>
<p>I am using Jenkins to automate the development process using a multibranch CI/CD pipeline. I'm trying to deploy a stateful application. I am using the &quot;Kubernetes Continuous Deploy Version1.0.0&quot; plugin for the deploy.</p>
<p>The pipeline runs correctly and as expected, except for one part:</p>
<p><a href="https://i.stack.imgur.com/s6RO4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s6RO4.png" alt="jenkins pipeline status page" /></a></p>
<p>The status is green, however, the stateful set isn't starting or updating on the k8s cluster. When I checked the status it seems like my plugin is skipping the YAML I have provided. The status from the &quot;deploying an app to Kubernetes&quot; stage:</p>
<pre><code>            Starting Kubernetes deployment
        Loading configuration: /var/lib/jenkins/workspace/algo-1_master/Preprod/Trader/statefulset_algo_1.yaml
        Skipped unsupported resource: StatefulSet(apiVersion=apps/v1, kind=StatefulSet,
     metadata=ObjectMeta(annotations={}, clusterName=null, creationTimestamp=null, 
    deletionGracePeriodSeconds=null, deletionTimestamp=null, finalizers=[], 
    generateName=null, generation=null, initializers=null, labels={},
     name=algo-1, namespace=1-algo-prod, ownerReferences=[],
     resourceVersion=null, selfLink=null, uid=null, additionalProperties={}),
     spec=StatefulSetSpec(podManagementPolicy=null, replicas=4, revisionHistoryLimit=null, 
    selector=LabelSelector(matchExpressions=[], 
    matchLabels={app=algo-1}, additionalProperties={}), serviceName=algo-1
    , template=PodTemplateSpec(metadata=ObjectMeta(annotations={},
         clusterName=null, creationTimestamp=null, deletionGracePeriodSeconds=null, deletionTimestamp=null, finalizers=[], generateName=null, generation=null,
         initializers=null, labels={app=algo-1}, name=null, namespace=null, ownerReferences=[],
 resourceVersion=null, selfLink=null,
     uid=null, additionalProperties={}), spec=PodSpec(activeDeadlineSeconds=null, affinity=null, automountServiceAccountToken=null, containers=[Container(args=[], command=[], env=[EnvVar(name=PODNAME, value=null,
         valueFrom=EnvVarSource(configMapKeyRef=null, fieldRef=ObjectFieldSelector(apiVersion=null, 
        fieldPath=metadata.name, additionalProperties={}), resourceFieldRef=null,
 secretKeyRef=null, additionalProperties={}), additionalProperties={}), EnvVar(name=API_ID, value=null, 
        valueFrom=EnvVarSource(configMapKeyRef=null, fieldRef=null, resourceFieldRef=null,
         secretKeyRef=SecretKeySelector(key=api-id, name=alpaca-api, optional=null,
 additionalProperties={}), additionalProperties={}), additionalProperties={}),
         EnvVar(name=API_KEY, value=null, valueFrom=EnvVarSource(configMapKeyRef=null, fieldRef=null, resourceFieldRef=null, 
secretKeyRef=SecretKeySelector(key=secret-key, name=alpaca-api, optional=null, additionalProperties={}), 
        additionalProperties={}), additionalProperties={})], envFrom=[], image=arieltar/algo-1,
 imagePullPolicy=Always, lifecycle=null, livenessProbe=null, name=algo-1, ports=[], readinessProbe=null, resources=null, securityContext=null,
         stdin=null, stdinOnce=null, terminationMessagePath=null, terminationMessagePolicy=null,
 tty=null, volumeDevices=[], volumeMounts=[], workingDir=null, additionalProperties={})], dnsConfig=null, 
        dnsPolicy=null, hostAliases=[], hostIPC=null, hostNetwork=null, hostPID=null,
 hostname=null, imagePullSecrets=[], initContainers=[], nodeName=null, nodeSelector={},
 priority=null, priorityClassName=null, restartPolicy=null, schedulerName=null, securityContext=null, 
        serviceAccount=null, serviceAccountName=null, subdomain=null, terminationGracePeriodSeconds=null, tolerations=[], volumes=[], additionalProperties={}),
 additionalProperties={}), updateStrategy=null, volumeClaimTemplates=[], additionalProperties={}), status=null, additionalProperties={})
            Finished Kubernetes deployment
</code></pre>
<p>My pipeline is as follows:</p>
<pre><code>pipeline {
    environment {
      dockerimagename = &quot;arieltar/algo-1&quot;
      dockerImage = &quot;&quot;
    }

    agent any

    stages {

      stage('Checkout Source') {
        steps {
          git 'https://github.com/finance-dataspider/spiderdoc.git'
        }
      }

      stage('Build image') {
        steps{
          script {
            dockerImage = docker.build(dockerimagename,&quot;./Preprod/Trader/&quot;)
          }
        }
      }

      stage('Pushing Image') {
        environment {
                registryCredential = 'dockerhub-reg'
            }
        steps{
          script {
            docker.withRegistry( 'https://registry.hub.docker.com', registryCredential ) {
              dockerImage.push(&quot;latest&quot;)
            }
          }
        }
      }

      stage('Deploying App to Kubernetes') {
        steps {
          script {
            kubernetesDeploy(configs: &quot;Preprod/Trader/statefulset_algo_1.yaml&quot;, kubeconfigId: &quot;kubernetes&quot;)
          }
        }
      }

    }

  }
</code></pre>

Ariel Tarayants
<p>Easy solution don't use a plugin if it's not supporting stateful set and you want to deploy it.</p>
<p>Just install <strong>kubectl</strong> into bash and use it directly to apply the YAML</p>
<pre><code>stage('Deploy Image') {
      steps{
        script {
          docker.withRegistry( '', registryCredential ) {
            dockerImage.push(&quot;$BUILD_NUMBER&quot;)
             dockerImage.push('latest')

          }
        }
      }
    }
    stage('Deploy to K8s') {
      steps{
        script {
          sh &quot;sed -i 's,TEST_IMAGE_NAME,harshmanvar/node-web-app:$BUILD_NUMBER,' deployment.yaml&quot;
          sh &quot;cat deployment.yaml&quot;
          sh &quot;kubectl --kubeconfig=/home/ec2-user/config get pods&quot;
          sh &quot;kubectl --kubeconfig=/home/ec2-user/config apply -f deployment.yaml&quot;
        }
      }
    }
</code></pre>
