评估github操作中的环境变量工作流程

发布于 2025-02-13 04:27:10 字数 1193 浏览 0 评论 0原文

我很肯定这很容易,但是我无法准确地追踪我想要的东西。我有一个执行构建并创建工件的工作流程。工件在文件名中使用环境变量。到目前为止,一切都很好。然后,当我尝试将此文件名传递到 s3上传操作发现由于环境变量未评估。这是我工作流程的相关部分:

  - name: Build project
    run: ./build_project.sh

  - run: ls -l "${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip" # file exists in directory
  - run: echo "${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip" # echo returns the location properly

  - uses: hkusu/s3-upload-action@v2
    id: upload # specify some ID for use in subsequent steps
    with:
      aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
      aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      aws-region: "eu-west-2"
      aws-bucket: ${{ secrets.AWS_BUCKET }}
      file-path: "${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip" # Error: file does not exist
      output-file-url: "true" # specify true
  - name: Show URL
    run: echo '${{ steps.upload.outputs.file-url }}' # use this output

我的实际问题是如何替换“ $ {github_workspace}/build/$ {file_name} .zip”用文件路径和名称实际运行工作流程时。另外,我尝试了一些不同的组合 - 没有引号,没有卷发括号,两者都不是。

I'm positive that this is something easy but I'm not able to track down exactly what I'm looking for. I have a workflow that performs a build and creates an artifact. The artifact uses an environment variable in the filename. So far so good. Then when I try to pass this file name to S3 upload action, it isn't found because the environment variable isn't evaluated. Here is the relevant part of my workflow:

  - name: Build project
    run: ./build_project.sh

  - run: ls -l "${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip" # file exists in directory
  - run: echo "${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip" # echo returns the location properly

  - uses: hkusu/s3-upload-action@v2
    id: upload # specify some ID for use in subsequent steps
    with:
      aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
      aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      aws-region: "eu-west-2"
      aws-bucket: ${{ secrets.AWS_BUCKET }}
      file-path: "${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip" # Error: file does not exist
      output-file-url: "true" # specify true
  - name: Show URL
    run: echo '${{ steps.upload.outputs.file-url }}' # use this output

My actual question is how to replace "${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip" with the file path and name when it actually runs the workflow. Also, I have tried a few of different combinations of things - no quotes, no curly braces, neither, both.

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

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

发布评论

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

评论(1

东走西顾 2025-02-20 04:27:10

由于这些参数传递到s3-upload-action,因此该行为取决于操作是否扩展了shell参数,但是输入值实际上是即将

${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip

到期的。

可以使用表达式

      file-path: ${{ github.workspace }}/build/${{ env.FILE_NAME }}.zip

您 假设环境变量像通过shell评估时一样在任何地方扩展,例如运行:步骤,但事实并非如此。

Since these parameters are passed through to the s3-upload-action, the behaviour depends on whether the action expands shell parameters or not, but the input value will be literally

${GITHUB_WORKSPACE}/build/${FILE_NAME}.zip

i.e., unexpanded.

You can use expressions to work around this:

      file-path: ${{ github.workspace }}/build/${{ env.FILE_NAME }}.zip

You maybe have assumed that environment variables expand everywhere as they do when evaluated by a shell, such as in a run: step, but they don't.

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