0

I copy my .env.example file:

    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"

But I also want to have override variables in the .env file. I have tried:

    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"
      env:
        DB_DATABASE: test_db
        DB_USER: root
        DB_PASSWORD: root

But the new variables I assign in the YAML file do not override variables in the .env file. How can I override variables in my .env file in the Actions script?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
panthro
  • 22,779
  • 66
  • 183
  • 324
  • I don't see why you'd expect that they would - all you're doing there is copying a file. Set the env map in the step where those variables are actually _used_. – jonrsharpe Apr 05 '22 at 10:48
  • I have also tried to use those new `env` in the step used, it still uses the ones from the original `env` file. – panthro Apr 05 '22 at 10:51
  • 1
    Could you give a [mre] _of that_? What you've shown here isn't going to work because the `env` is only set _for that step_, and they're not actually _used_ in the copy operation. I suppose you could add to the `.env` file after copying it, as shown in e.g. https://stackoverflow.com/a/63350136/3001761, which _would_ use the env vars set in this step. – jonrsharpe Apr 05 '22 at 10:54

0 Answers0