<p>I have deplyonment.yml file which looks like below :</p>
<pre><code>apiVersion : apps/v1
kind: Deployment
metadata:
  name: worker
spec:
  progressDeadlineSeconds: 3600
  replicas: 1
  selector:
    matchLabels:
      app: worker
  template:
    metadata:
      labels:
        app: worker
    spec:
      containers:
        - name: worker         
          image: $(RegistryName)/$(RepositoryName):$(Build.BuildNumber)
          imagePullPolicy: Always 
</code></pre>
<p>But I am not able to use $(RegistryName) and $(RepositoryName) as I am not sure how to even initialize this and assign a value here.</p>
<p>If I specify something like below</p>
<pre><code>image: XXXX..azurecr.io/werepo:$(Build.BuildNumber)
</code></pre>
<p>It worked with the direct static and exact names. But I don't want to hard core registry and repository name.</p>
<p>Is there any way to replace this dynamically? just like the way I am passing these in task</p>
<pre><code>  - task: KubernetesManifest@0
            displayName: Deploy to Kubernetes cluster
            inputs:
              action: deploy
              kubernetesServiceConnection: 'XXXX-connection'
              namespace: 'XXXX-namespace'
              manifests: |
                $(Pipeline.Workspace)/manifests/deployment.yml 
              containers: |
                $(Registry)/$(webRepository):$(Build.BuildNumber) 
</code></pre>

JARVIS
<p>You can do something like</p>
<p><strong>deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: test-image
  labels:
    app: test-image
spec:
  selector:
    matchLabels:
      app: test-image
      tier: frontend
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: test-image
        tier: frontend
    spec:
      containers:
      - image: TEST_IMAGE_NAME
        name: test-image
        ports:
        - containerPort: 8080
          name: http
        - containerPort: 443
          name: https
</code></pre>
<p>in CI step or run <code>sed</code> command in ubuntu like</p>
<pre><code>steps:
- id: 'set test core image in yamls'
  name: 'ubuntu'
  args: ['bash','-c','sed -i &quot;s,TEST_IMAGE_NAME,gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA,&quot; deployment.yaml']
</code></pre>
<p>above will resolve your issue.</p>
<p>Above command simply find &amp; replace <code>TEST_IMAGE_NAME</code> with variables that creating the docker <strong>image URI</strong>.</p>
<p><strong>Option : 2</strong> <strong>kustomization</strong></p>
<p>If you want to do it with customization</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- service.yaml
- deployment.yaml
namespace: default
commonLabels:
  app: myapp
images:
- name: myapp
  newName: registry.gitlab.com/jkpl/kustomize-demo
  newTag: IMAGE_TAG
</code></pre>
<p>sh file</p>
<pre><code>#!/usr/bin/env bash
set -euo pipefail

# Set the image tag if not set
if [ -z &quot;${IMAGE_TAG:-}&quot; ]; then
    IMAGE_TAG=$(git rev-parse HEAD)
fi

sed &quot;s/IMAGE_TAG/${IMAGE_TAG}/g&quot; k8s-base/kustomization.template.sed.yaml &gt; location/kustomization.yaml
</code></pre>
<p>Demo github : <a href="https://gitlab.com/jkpl/kustomize-demo" rel="nofollow noreferrer">https://gitlab.com/jkpl/kustomize-demo</a></p>
