Setting job environment dynamically doesn't work when using key-value format
See original GitHub issueDescribe the bug I was trying to set the job environment dynamically so I can use my GitHub production & staging environment secrets in a single workflow.
To Reproduce Steps to reproduce the behavior:
name: Set Job Enviroment Dynamically
on:
workflow_dispatch:
jobs:
set_environment:
outputs:
my_env: ${{ steps.setenv.outputs.my_env }}
runs-on: ubuntu-latest
steps:
- id: setenv
run: echo "::set-output name=my_env::production"
use_outputs_environemnt_directly:
needs: set_environment
environment: ${{ needs.set_environment.outputs.my_env }}
runs-on: ubuntu-latest
steps:
- name: Testing job environment
run: echo "Hello From Production Envrionment."
See failing workflow: failure.yaml
Expected behavior The environment should be set to production.
What’s not working?
I get the below error:
The workflow is not valid. .github/workflows/job-environment-test-ko.yml (Line: 15, Col: 18): Unrecognized named-value: 'needs'. Located at position 1 within expression: needs.set_environment.outputs.en
Workaround found
Using object format for jobs environment fixes the issue
environment:
name: ${{ needs.set_environment.outputs.my_env }}
See successful workflow: success.yaml
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Use dynamic input value for Environment in GitHub Actions ...
I'm trying to make a GitHub Actions workflow where one job has a dynamic value to its environment setting. https://docs.github.com/en/actions/ ...
Read more >Environment Variables section not showing in Dynamic Content
I'm testing using environment variables in a Flow and when I try to reference the environment variable in a Flow, the "Environment.
Read more >Artifacts Filename Cannot Be Set with Dynamic Variables
It looks like custom variables are not being exposed correctly to the job resulting in the wrong artifact file name. Do you know...
Read more >Environment Variables: What They Are and How To Use ...
Environment variables are used to store app secrets and configuration data, which are retrieved by your running app when needed.
Read more >Dynamic body with dynamic variables - Just getting started
Hello, I need to send a dynamic body depending on the environment where I'm working, but since the amount of things that will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Will being able to dynamically specify environment name be added at any point? This makes selecting an environment from a
workflow_dispatch
event a lot more complicated.Thanks for the report!
We support expressions only in https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-environment-name-and-url with mappings.
environment: blah
exists for short form notations, and it doesn’t support contexts.