Is it possible to set the "environment" of a job only if a defined condition is true ? So for example only if it was passed as INPUT ?
jobs:
test_workflow:
runs-on: ubuntu-latest
environment: EXAMPLE <-- This one
steps:
- uses: actions/checkout@v3
My use case: Im using a reusable_workflow and i only want to add the environment if it was passed to the workflow.
environment does not accept null/false but only string or object.
Would it work to set the default of the input to an empty string and to "example" in the other call ? What is the consequence of setting it to an empty string ?
Ref : https://docs.github.com/en/actions/using-jobs/using-environments-for-jobs
2
Answers
SOLUTION:
It is possible to set the ENVIRONMENT to an empty string and it will be treated like its not set. So i defined my INPUT with the empty string default and only pass a value if needed!.
You can set an If statement at the beginning of a step that can set an environment variable with $GITHUB_ENV. Here is an example:
Then you can access this variable using ${{ env.EAMPLE }}