Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to have .env file at pipeline job level in azure devops

Could you please suggest what is the best way to have .env file available for my azure devops pipeline. (Note we are ignoring the .env file to be pushed to Git repository)

My Node.js utility application code base is in azure-devops Git.

I have an azure build pipeline (YML version) which is a CI pipeline (doing just compile & test).

Unit test uses API call which needs API secret token to run.

These tokens are stored in .env file (I used dotenv package of Node.js) But we are not pushing .env file to Git.

So how should I make .env file available to my CI pipeline.

like image 362
Sanjesh M Avatar asked Dec 03 '22 17:12

Sanjesh M


1 Answers

You can use secure files on azure devops.

1, First upload the .env file to azure devops Secure file

Go to your azure devops project portal. Pipelines--> Library--> Secure files--> +Secure file.

enter image description here

2, Then add Download Secure file Task in your yaml pipeline to download .env file to the agent.

 - task: DownloadSecureFile@1
      inputs:
        secureFile: '.env'

if the task is given the name mySecureFile, its path can be referenced in the pipeline as $(mySecureFile.secureFilePath). Alternatively, downloaded secure files can be found in the directory given by $(Agent.TempDirectory)

3, Then you can Copy File task to copy the .env file to the right place.

like image 126
Levi Lu-MSFT Avatar answered Dec 31 '22 16:12

Levi Lu-MSFT