schrom
schrom

Reputation: 1641

Github Actions - How to use a variable defined in env in the same env section?

I'd like to reuse an env variable defined in the same section.

This does not work

env:
   HOST: example.com
   URL: $HOST/foo.html

It will just yield a verbose "$HOST/foo.html" without host being resolved when used.

I also tried

env:
   HOST: example.com
   URL: ${{ env.HOST }}/foo.html

this just tells me unrecognized named-value: 'env'

Upvotes: 3

Views: 1935

Answers (1)

DannyB
DannyB

Reputation: 14776

According to this GitHub Actions forum thread, you can't.

The proposed solution there is to set the base environment variable, at the job level, and then you can use it at the step level.

jobs:
  test:
    runs-on: ubuntu-latest
    name: Test

    env:
      HOST: example.com

    steps:
    - env:
        URL: ${{ env.HOST }}/foo.html
      run: echo $URL

I agree with your intuition - I also expected it to work.

Upvotes: 6

Related Questions