Create GitHub Deployment Environment

Action ID: github:environment:create
NPM Package:

@backstage/plugin-scaffolder-backend-module-github

Description

Creates Deployment Environments

Input Schema

PropertyTypeDescriptionRequired
namestring-
tokenstringThe token to use for authorization to GitHub
repoUrlstringAccepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username
secretsobject-
reviewersarrayReviewers for this environment. Must be a list of Backstage entity references.
waitTimernumberThe time to wait before creating or updating the environment (in milliseconds)
preventSelfReviewbooleanWhether to prevent self-review for this environment
customTagPolicyNamesarray-
environmentVariablesobject-
deploymentBranchPolicyobject-
customBranchPolicyNamesarray-

Output Schema

No output schema defined for this action.

Usage Examples

Create a staging environment with variables and secrets

Creates a staging environment in a repository with environment variables and encrypted secrets. Use this after the repo exists, typically following publish:github.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      values:
        repoName: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}

  - id: create-staging-environment
    action: github:environment:create
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.owner }}
      name: staging
      environmentVariables:
        NODE_ENV: staging
        LOG_LEVEL: info
        FEATURE_FLAGS: enable-x,disable-y
      secrets:
        STAGING_API_KEY: ${{ parameters.stagingApiKey }}
        DOCKER_REGISTRY_PASSWORD: ${{ parameters.dockerRegistryPassword }}
      token: ${{ parameters.githubToken }}

Create a production environment with required reviewers

Creates a production environment that requires review and prevents self review. Add a short wait to avoid race conditions right after repository creation with publish:github.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      values:
        repoName: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}

  - id: create-production-environment
    action: github:environment:create
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.owner }}
      name: production
      preventSelfReview: true
      reviewers:
        - group:default/release-managers
        - user:default/jlee
      waitTimer: 5000
      token: ${{ parameters.githubToken }}

Create a preview environment with custom branch and tag policies

Creates a preview environment that uses named custom branch and tag policies configured in your GitHub organization. Use this to restrict deployments to specific branch or tag policies.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      values:
        repoName: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}

  - id: create-preview-environment
    action: github:environment:create
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.owner }}
      name: preview
      customBranchPolicyNames:
        - preview-branches
        - rc-only
      customTagPolicyNames:
        - release-tags-only
      token: ${{ parameters.githubToken }}

Create an ephemeral PR environment

Creates an ephemeral environment named with a pull request number. Use this in templates that scaffold per PR resources for testing.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      values:
        repoName: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}
        prNumber: ${{ parameters.prNumber }}

  - id: create-ephemeral-pr-environment
    action: github:environment:create
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.owner }}
      name: pr-${{ parameters.prNumber }}
      environmentVariables:
        PR_NUMBER: "${{ parameters.prNumber }}"
        NODE_ENV: test
      secrets:
        TESTING_TOKEN: ${{ parameters.testingToken }}
      token: ${{ parameters.githubToken }}

Create a blue environment for blue green deployments

Creates a blue environment with custom tag policy names and minimal configuration. Use this alongside a green environment created in another step.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      values:
        repoName: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}

  - id: create-blue-environment
    action: github:environment:create
    input:
      repoUrl: github.com?repo=${{ parameters.repoName }}&owner=${{ parameters.owner }}
      name: blue
      customTagPolicyNames:
        - stable-releases
      secrets:
        BLUE_API_TOKEN: ${{ parameters.blueApiToken }}
      token: ${{ parameters.githubToken }}