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

Viewed 850

If I have the following section in my github action workflow yaml:

env:
  fullySupportedScalaVersions: "2.13.6"

  test:
    runs-on: ubuntu-latest

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

I receive an error message like this:

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) }}'

How do I solve or circumvent this problem?

The above is observed in the following workflow: https://github.com/tek/splain/blob/6b12e57954aae0852e9b948e12ef5637c478b53d/.github/workflows/main.yml

1 Answers

The problem is related to the syntax used on the continue-on-error: field.

I made it worked updating it to

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

So that the workflow didn't return the error anymore.

It returns an error during the execution, but it is for another reason not related to this topic.


From what I understood, the continue-on-error filed doesn't work the same way as the if field for expressions.

For example, when you use expressions in an if conditional, you do not need to use the expression syntax ${{ }} because GitHub automatically evaluates the if conditional as an expression.

But it's not the case with continue-on-error, expressions don't seem to be automatically detected by Github, so you need to add the brackets back. Moreover, Github didn't recognised env.FULLY_SUPPORTED_SCALA_VERSIONS directly there, so I had to add brackets here as well (probably due to the field specifications).

Related