Azure Pipeline 将安全文件复制到构建文件夹中

发布于 2025-01-11 15:19:44 字数 1736 浏览 0 评论 0原文

我有一个 vite/svelte 项目,它使用 .env 文件进行环境设置。我还有一个 Azure Pipeline,其中包含一个安全文件 .env.staging,该文件位于关联存储库的 .gitignore 列表中。我想下载这个安全文件,将其复制到我的构建目录,然后在运行 vite build --mode staging 时读取其内容(嗯,npm run build:staging 其中包括 vite build...)

当从我的机器本地运行时 npm run build:staging 按预期工作并读取 .env.staging 文件,但是,在管道中使用时似乎会被忽略,我在做什么吗 错误的?

这是我的 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"

我不确定 CopyFiles@2 是否按照我的预期执行,因为它只是匹配 content 参数来复制任何匹配的文件,这可能是0 如果我写错了...

另一方面,我也尝试使用 $(dotenvStaging.secureFilePath) 作为内容参数,但它似乎也没有做任何事情。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

油饼 2025-01-18 15:19:44

当然,我一发布就发现,我需要更新 CopyFiles 部分以指定 sourceFolder,显然它不喜欢我的内容的绝对文件路径。

  - task: CopyFiles@2
    inputs:
      sourceFolder: "$(Agent.TempDirectory)"
      contents: ".env.staging"
      targetFolder: "$(Agent.BuildDirectory)"
    displayName: "Import .env.staging"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文