How to store .env file in Jenkins workspace?

Viewed 1226

I have a freestyle project in Jenkins in which I fetch remote Github repo on every commit and then install it's dependencies and build the app in the workspace.

In the app I need to use env variables from the .env file, but on every new commit all files get removed from the workspace.

Is there a way to store .env file in the workspace directory? How to tell Jenkins to not remove this file?

1 Answers

You can set a pattern for files which shouldn't be deleted from Workspace (Build Environment -> Delete workspace before build starts -> Advanced):

WS deletion

Or you can prepare a complete build environment for your build (General -> Prepare an environment for the run). Perhaps you should use this if you use the SCP plugin and it cleans the works-space automatically. This section contains many options to define the environment, I guess you can find the proper one for you.

environment creation

Related