<p>Is there a way to pass GitHub Actions environment variables to the Kubernetes index file?</p>
<p>The workflow file, this part will get the run number:</p>
<pre><code>- name: Taggig
  run: |
    echo &quot;imageTag=${{ github.run_number }}&quot; &gt;&gt; $GITHUB_ENV
</code></pre>
<p>And I want to pass it to the index like -</p>
<p>Example:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: my-image:{{ env.imageTag }}
</code></pre>

Baequiraheal
<p>You can use <code>envsubst</code> as Azeem mentioned:</p>
<p>So you would have something like:</p>
<pre><code>containers:
  - name: my-container
    image: my-image:$imageTag
</code></pre>
<p>In your deployment file, then with <a href="https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html" rel="nofollow noreferrer"><code>envsubst</code></a> you would substitute that  <code>imageTag</code> environment variable with:</p>
<pre><code>envsubst &lt; deployment.yml 
</code></pre>
<p>Supposedly you named your deployment file as <code>deplyoment.template.yml</code>, you'd have an something like:</p>
<pre><code>steps:
  - name: Taggig
    run: |
      echo &quot;imageTag=${{ github.run_number }}&quot; &gt;&gt; $GITHUB_ENV
  - name: Render k8s manifests
    run: envsubst &lt; deployment.template.yml &gt; deployment.yml 
  
  - run: kubectl apply -f ./deployment.yml
</code></pre>
<hr />
<p>One other approach is to use <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-image-em-" rel="nofollow noreferrer"><code>kubectl set image</code></a>, for example:</p>
<pre><code>  - name: Taggig
    run: |
      echo &quot;imageTag=${{ github.run_number }}&quot; &gt;&gt; $GITHUB_ENV

  - run: kubectl set image -f deployment.template.yml  my-container=my-image:$imageTag --local -o yaml &gt; deployment.yml 

  - run: kubectl apply -f ./deployment.yml         
</code></pre>
<hr />
<p>Alternatively, you can use <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/" rel="nofollow noreferrer"><code>kustomize</code></a> or <a href="https://github.com/mikefarah/yq" rel="nofollow noreferrer"><code>yq</code></a> to set your <code>image:tag</code> value</p>
