Skip to content
Latchkey

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

  1. For a simple case use environment: production.
  2. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →