<p>I'm running a pipeline on gitlab which uses .gitlab-ci.yml and Dockerfile to build a image and push it to GCP container repository. Then I use that image to make deployment on Kubernetes.</p>
<p>I'm using CI/CD private variables to inject <strong>username(service_now_qa_username)</strong> and <strong>password(service_now_qa_password)</strong> and passing it as arguments to docker build command which are then used in <strong>Dockerfile</strong></p>
<p>This is what my gitlab-ci.yml file looks like</p>
<pre><code>variables:
        BUILD_ARGS: &quot;--build-arg USERNAME=$service_now_qa_username --build-arg PASSWORD=$service_now_qa_password&quot;
script:
   
    - docker build -t &quot;$IMAGE_NAME:$CI_COMMIT_REF_NAME&quot; -t &quot;$IMAGE_NAME:latest&quot; $BUILD_ARGS .
</code></pre>
<p>This is what my Dockerfile looks like:</p>
<pre><code>ARG USERNAME
ARG PASSWORD
ENV USER=$USERNAME
ENV PASS=$PASSWORD

ENTRYPOINT java -jar servicenowapi.jar -conf config.json -username ${USER} -password ${PASS}
</code></pre>
<p>Now I want to override these arguments of <strong>username</strong> and <strong>password</strong> using Kubernetes <strong>Deployment.yml</strong> and use Deployment.yaml file to override these arguments.</p>
<p>My end goal is to use Kubernetes Deployment.yaml for <strong>username</strong> and <strong>password</strong> and passed as arguments to Dockerfile.</p>

M Usama Alvi
<p><code>ARGS</code> are build-time variables so no way to pass values to ARGS at runtime.</p>
<p>By the way, you can override <code>entrypoint</code> as following in Kubernetes deployment and consume environment variables. (<code>entrypoint</code> in Dockerfile is <code>command</code> in Kubernetes container spec).</p>
<pre class="lang-bash prettyprint-override"><code>containers:
  - name: xxxx
    env:
    - name: USER
      value: &quot;Input your user&quot;
    - name: PASS
      value: &quot;Input your pass&quot;
    command: [&quot;java&quot;, &quot;-jar servicenowapi.jar -conf config.json -username $(USER) -password $(PASS)&quot;]
</code></pre>
<p>The main thing here is to define env vars and to use <code>$()</code> instead of <code>${}</code>.</p>
