Answers: <p>You can store secret file at Jenkins and use it for deployment.
  It can be achieved by using <a href="https://plugins.jenkins.io/credentials/" rel="nofollow noreferrer">Credentials</a> and <a href="https://plugins.jenkins.io/credentials-binding/" rel="nofollow noreferrer">Credentials Binding</a> plugins.</p>
  <ol>
  <li>Install Credentials Binding and Credentials plugins</li>
  <li>Select your user name in the top navigation bar.</li>
  <li>Select Credentials in the left pane.</li>
  <li>Under Stores from parent, select (global) in the Domains column.</li>
  <li>Select Add Credentials in the left pane.
  <a href="https://i.sstatic.net/wCUk4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wCUk4.png" alt="enter image description here" /></a></li>
  <li>insert into your pipeline script</li>
  </ol>
  <pre>  
  withCredentials([file(credentialsId: 'env', variable: 'mySecretEnvFile')]){
      sh 'cp $mySecretEnvFile $WORKSPACE'
  }
  </pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-01-05T19:32:21.080Z
Answers: 2021-01-05T19:32:21.080Z
Answers: Evgeny Anikiev
Body: <p>how to update the .env file in production while Jenkins deployment?
  we have not committed the .env file in git for security reasons.</p>
  
Tags: <jenkins><jenkins-pipeline>
Title: how to update .env file in production while Jenkins deployment
UserDisplayName: Subhash
ThreadText: # how to update .env file in production while Jenkins deployment
  
  (Asked by: username_0 on 2021-01-05)
  
  how to update the .env file in production while Jenkins deployment?
  we have not committed the .env file in git for security reasons.
  
  **Tags:** jenkins, jenkins-pipeline
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-05. Score: 4 | Accepted answer
  
  You can store secret file at Jenkins and use it for deployment.
  It can be achieved by using [Credentials](https://plugins.jenkins.io/credentials/) and [Credentials Binding](https://plugins.jenkins.io/credentials-binding/) plugins.
  
  1. Install Credentials Binding and Credentials plugins
  2. Select your user name in the top navigation bar.
  3. Select Credentials in the left pane.
  4. Under Stores from parent, select (global) in the Domains column.
  5. Select Add Credentials in the left pane.
     [![enter image description here](https://i.sstatic.net/wCUk4.png)](https://i.sstatic.net/wCUk4.png)
  6. insert into your pipeline script
  
  ```
    
  withCredentials([file(credentialsId: 'env', variable: 'mySecretEnvFile')]){
      sh 'cp $mySecretEnvFile $WORKSPACE'
  }
  
  ```
  
  
  ---
  
  