【问题标题】:How to use environment variable in github action job/continue-on-error section?如何在 github action job/continue-on-error 部分使用环境变量?
【发布时间】:2021-12-28 19:38:49
【问题描述】:

如果我的 github 操作工作流 yaml 中有以下部分:

env:
  fullySupportedScalaVersions: "2.13.6"

  test:
    runs-on: ubuntu-latest

    continue-on-error: ${{ contains(env.fullySupportedScalaVersions, matrix.scalaVersion) }}

我收到如下错误消息:

Invalid workflow file : .github/workflows/main.yml#L38
The workflow is not valid. .github/workflows/main.yml (Line: 38, Col: 24): Unrecognized named-value: 'env'. Located at position 10 within expression: contains(env.fullySupportedScalaVersions, matrix.scalaVersion) .github/workflows/main.yml (Line: 38, Col: 24): Unexpected value '${{ contains(env.fullySupportedScalaVersions, matrix.scalaVersion) }}'

我该如何解决或规避这个问题?

在以下工作流程中观察到上述情况: https://github.com/tek/splain/blob/6b12e57954aae0852e9b948e12ef5637c478b53d/.github/workflows/main.yml

【问题讨论】:

    标签: github continuous-integration github-actions


    【解决方案1】:

    问题与continue-on-error: 字段上使用的语法有关。

    我让它工作更新到

    continue-on-error: ${{ contains( '${{ env.FULLY_SUPPORTED_SCALA_VERSIONS }}', '${{ matrix.scalaVersion }}') }}
    
    

    这样工作流就不再返回错误了。

    在执行过程中返回错误,但由于其他原因与本主题无关。


    据我了解,continue-on-error 字段的工作方式与表达式的 if 字段不同。

    例如,当您在 if 条件中使用表达式时,您不需要使用表达式语法 ${{ }},因为 GitHub 会自动将 if 条件作为表达式求值。

    但是continue-on-error不是这样,Github似乎不会自动检测到表达式,所以你需要把括号加回来。而且,Github 并没有直接在那里识别env.FULLY_SUPPORTED_SCALA_VERSIONS,所以我也不得不在这里添加括号(可能是由于字段规范)。

    【讨论】:

    • 非常感谢!验证后会将您的答案发布到问题跟踪器
    猜你喜欢
    • 1970-01-01
    • 2020-12-10
    • 2021-06-19
    • 1970-01-01
    • 2021-09-24
    • 2021-10-08
    • 1970-01-01
    • 2020-05-09
    • 2023-03-06
    相关资源
    最近更新 更多