Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'

like image 766
schrom Avatar asked May 23 '26 11:05

schrom


1 Answers

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.

like image 115
DannyB Avatar answered May 26 '26 19:05

DannyB