GitHub Actions "environment must be a string"
The environment key takes either a string name or a mapping with name and url. A bare list or wrong shape fails validation.
What this error means
The workflow is rejected at the environment key with a type error stating a string was expected.
github-actions
The workflow is not valid. .github/workflows/deploy.yml (Line: 7): Invalid type for 'environment', expected a string or a mapping with 'name'Common causes
environment given as a list
A job targets one environment; a list is not valid.
Mapping without name
When using the mapping form, name is required and url is optional.
How to fix it
Use a string name or name/url mapping
- For a simple case use environment: production.
- For a deployment URL use the mapping form with name and url.
.github/workflows/deploy.yml
environment:
name: production
url: ${{ steps.deploy.outputs.page_url }}How to prevent it
- Stick to the documented environment shapes.
- Run actionlint to validate the environment field.
Related guides
GitHub Actions environment protection rules blocked the jobFix the GitHub Actions situation where a deployment is blocked or waiting because environment protection rule…
GitHub Actions reusable workflow uses must be a valid pinned referenceFix the GitHub Actions error where a reusable workflow uses value is not a valid owner/repo/.github/workflows…
GitHub Actions "Invalid type" for env or with valuesFix the GitHub Actions "Invalid type" error for env or with values caused by passing a list or mapping where…