title: How to tag ECR Docker Images as prod and non-prod
body: <p>I have a CI/CD pipeline with a single JenkinsBuild.jk  setup which is automatically triggered whenever a pull Request has been merged to master branch .</p>
  <p>I have bunch of commands like 'docker build' and 'docker push' in JenkinsBuild which creates version of docker-images like:</p>
  <p>x.36, x.37, x.38, x.39, x.40, x.41 , x.42, x.43, x.44, x.45 (Added prefix &quot;x.&quot; to delete untagged images).</p>
  <p>Now the problem arises when I have to deploy few of those dockerImages to prod and not all of them. Example - x.36 , x.40 and x.45 are images deployed to prod and rest all images are used for non-prod environment for testing code.</p>
  <p>When I apply the below ECR lifecycle policy, it keeps top 5 images , hence all those versions which were not deployed to prod are also stored whereas which are most recently deployed are deleted. Example : Top 5 images i.e x.41 , x.42, x.43, x.44, x.45 are stored in ECR ,and most recently prod dockerImages i.e. x.36 , x.40 are deleted due to below policy ( x.45 is not deleted as it was one of the top 5 images).</p>
  <pre><code>{
        &quot;rulePriority&quot;: 1,
        &quot;description&quot;: &quot;Keep last 5 images&quot;,
        &quot;selection&quot;: {
          &quot;tagStatus&quot;: &quot;tagged&quot;,
          &quot;tagPrefixList&quot;: [&quot;x.&quot;],
          &quot;countType&quot;: &quot;imageCountMoreThan&quot;,
          &quot;countNumber&quot;: 5
        },
        &quot;action&quot;: {
          &quot;type&quot;: &quot;expire&quot;
        }
      }
  </code></pre>
  <p>Can someone help me how ECR policy can only delete non-prod dockerImages ?</p>
  <p>or</p>
  <p>How can I override the dockerImages during prod deployment as p.36, p.40, p.45 using JenkinsDeploy.jk ?</p>
  <p>Please suggest if you can. Thank you for reading my post.</p>