<p>I am trying to automate my deployment to Azure AKS, but trying to work out how to reference the image name in my manifest file. At the moment I have commented out the image name in the manifest file so see if that works but getting an error:</p>
<blockquote>
<p>##[error]TypeError: Cannot read property 'trim' of undefined</p>
</blockquote>
<p><strong>This is my  Github workflow file:</strong></p>
<pre><code>on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    
    - uses: Azure/docker-login@v1
      with:
        login-server: registry.azurecr.io
        username: ${{ secrets.REGISTRY_USERNAME }}
        password: ${{ secrets.REGISTRY_PASSWORD }}
    
    - run: |
        docker build . --file Dockerfile_nginx -t registry.azurecr.io/k8sdemo:${{ github.sha }}
        docker push registry.azurecr.io/k8sdemo:${{ github.sha }}
      
    - uses: Azure/k8s-set-context@v1
      with:
        kubeconfig: ${{ secrets.KUBE_CONFIG }}
      

    - uses: Azure/k8s-deploy@v1
      with:
        manifests: |
          k8s/mg-k8s/nginx.yaml
        images: |
          registry.azurecr.io/k8sdemo:${{ github.sha }}
        imagepullsecrets: |
          secret
</code></pre>
<p><strong>This is my manifest file:</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginxstaticservice
  namespace: mg-staging
  labels:
    app: nginxstatic
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
  # selector:
  #   app: nginxstatic

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginxstatic-deployment
  namespace: mg-staging
  labels:
    app: nginxstatic
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginxstatic
  template:
    metadata:
      labels:
        app: nginxstatic
    spec:
      containers:
      - name: nginxstatic
        # image: 
        imagePullPolicy: &quot;Always&quot;
        ports:
        - containerPort: 80

        volumeMounts:
          - name: nginx-config
            mountPath: /etc/nginx/conf.d
      volumes:
        - name: nginx-config
          configMap:
            name: nginx-configmap
      imagePullSecrets:
      - name: secret
</code></pre>

Rutnet
<p>Update: @Rutnet figured out the way to pass the new tag using <code>Azure/k8s-deploy1@1</code> action. From the <a href="https://github.com/Azure/k8s-deploy" rel="nofollow noreferrer">docs</a>:</p>
<blockquote>
<p>(Optional) Fully qualified resource URL of the image(s) to be used for
substitutions on the manifest files. This multiline input accepts
specifying multiple artifact substitutions in newline separated form.
For example -</p>
<pre><code>images: |   
contosodemo.azurecr.io/foo:test1  
contosodemo.azurecr.io/bar:test2
</code></pre>
<p>In this example, all references to
<code>contosodemo.azurecr.io/foo</code> and <code>contosodemo.azurecr.io/bar</code> are searched
for in the image field of the input manifest files. For the matches
found, the tags test1 and test2 are substituted.</p>
</blockquote>
<p>Based on the documentation, the manifest file needs to have references to the original image with a default tag. The action will replace the tags with the ones specified. The manifest in question has the <code>image</code> commented. It should have been something like:</p>
<pre class="lang-yaml prettyprint-override"><code>    spec:
      containers:
      - name: nginxstatic
        image: registry.azurecr.io/k8sdemo:some_tag
</code></pre>
<hr />
<p>Original Reply:</p>
<p>There are several ways of achieving this. You can use templating tools like <a href="https://helm.sh/docs/intro/quickstart/" rel="nofollow noreferrer">Helm</a> or <a href="https://github.com/kubernetes-sigs/kustomize" rel="nofollow noreferrer">Kustomize</a>. In this case, you can just use <a href="https://askubuntu.com/a/20416">sed</a> before you apply the manifest. Add a place holder in the manifest file and replace that with sed inline. See the following example:</p>
<pre><code>...
- run: |
    sed -i.bak &quot;/NGINX_IMAGE_URL/registry.azurecr.io\/k8sdemo:${{ github.sha }}&quot; k8s/mg-k8s/nginx.yaml

- uses: Azure/k8s-deploy@v1
      with:
        manifests: |
          k8s/mg-k8s/nginx.yaml
        images: |
          registry.azurecr.io/k8sdemo:${{ github.sha }}
        imagepullsecrets: |
          secret
...
</code></pre>
<p>Add the NGINX_IMAGE_URL place holder in the manifest file:</p>
<pre><code>...
    spec:
      containers:
      - name: nginxstatic
        image: NGINX_IMAGE_URL
...
</code></pre>
<p>HTH</p>
