<p>Currently I am working with implementation demo of CI/CD pipeline using Jenkins and kubernetes. I am created one Jenkins pipeline job and added every step in my Jenkinsfile. For kubernetes , I created deployment and service YAML files for Kubernetes resources.</p>

<p><strong>Image Version Management In deployment</strong></p>

<p>For each commit in my SVN repository , I am creating docker images by adding the tag as build number through Jenkins environment variable.</p>

<pre><code>image:1
image:2
.
.
image:n
</code></pre>

<p><strong>Confusion</strong></p>

<p>If I am using <code>kubectl set image</code> command for updating my deployment in my Jenkinsfile deployment stage , then It will work for first commit ? </p>

<p>I felt this confusion , because command says that it is for updating the deployment if there is change in image defined in YAML file. So If I am changing image for each commit according to build number( image-name:buildnumber) , then if there is no deployment exits , it will work for first time?</p>

<p>So I can think of multiple ways, one a bit hacky and other that I like. You can decide based on waht is best suited for you.</p>

<p><strong>Solution 1</strong> - You can add a simple conditional check-in your Jenkins, for the first time if deployment does not exists create it and set it to the first image. And from the second commit onwards update.</p>

<p>OR</p>

<p><strong>Solution 2</strong> - Think of it as each repository or service should have its own <code>deployment.yml</code> within it. So when for first time code is checked-in you can use that yml to check if deployment already exists ? if it does not just create the development with <code>kubectl apply myapp.yml</code> and for the second commit <code>kubectl set image</code> will work.</p>
