how to update the .env file in production while Jenkins deployment? we have not committed the .env file in git for security reasons.


You can store secret file at Jenkins and use it for deployment. It can be achieved by using Credentials and 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
  6. insert into your pipeline script
withCredentials([file(credentialsId: 'env', variable: 'mySecretEnvFile')]){
    sh 'cp $mySecretEnvFile $WORKSPACE'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.