簡體   English   中英

如何在 github 操作作業/錯誤繼續部分中使用環境變量?

[英]How to use environment variable in github action job/continue-on-error section?

如果我的 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

該問題與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 ,所以我也不得不在這里添加括號(可能是由於字段規范)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM