Reputation: 1747
I have a vite/svelte project which uses .env
files for environment settings. I also have an Azure Pipeline which contains a secure file .env.staging
this is on the .gitignore list of the associated repo. I'd like to download this secure file, copy it to my build directory, and then have its contents read when I run vite build --mode staging
(well, npm run build:staging
which includes vite build...)
When run locally from my machine npm run build:staging
works as expected and reads the .env.staging
file, however, it seems to get ignored when used in the pipeline, am I doing anything wrong?
Here's my YML:
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadSecureFile@1
name: "dotenvStaging"
inputs:
secureFile: '.env.staging'
displayName: "Download .env.staging"
- task: NodeTool@0
inputs:
versionSpec: 14.15.4
displayName: "Install Node.JS"
- task: CopyFiles@2
inputs:
contents: "$(Agent.TempDirectory)/.env.staging"
targetFolder: "$(Agent.BuildDirectory)"
displayName: "Import .env.staging"
- script: npm install
displayName: "npm install"
- script: npm run build:staging
displayName: "npm run build:staging"
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: 'dist'
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
#replaceExistingArchive: true
#verbose: # Optional
#quiet: # Optional
displayName: "Create archive"
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
ArtifactName: 'drop'
publishLocation: 'Container'
displayName: "Publish archive"
I'm not sure if CopyFiles@2
is doing what I expect or not as it just matches the content
parameter to copy whatever files match, which could be 0 if I'm writing it wrong...
On another note, I also tried using $(dotenvStaging.secureFilePath)
as the content parameter, but it doesn't seem to do anything either.
Upvotes: 4
Views: 6158
Reputation: 1747
Naturally I figured it out as soon as I posted, I needed to update the CopyFiles part to specify sourceFolder, clearly it didn't like my absolute file path for content.
- task: CopyFiles@2
inputs:
sourceFolder: "$(Agent.TempDirectory)"
contents: ".env.staging"
targetFolder: "$(Agent.BuildDirectory)"
displayName: "Import .env.staging"
Upvotes: 11