Skip to content

Set-GitHubEnvironment

SYNOPSIS

Create or update an environment.

SYNTAX

Default (Default)

Set-GitHubEnvironment -Owner <String> -Repository <String> -Name <String> [-WaitTimer <Int32>]
 [-DeploymentBranchPolicy <String>] [-Context <Object>] [-ProgressAction <ActionPreference>] [-WhatIf]
 [-Confirm] [<CommonParameters>]

WithReviewers

Set-GitHubEnvironment -Owner <String> -Repository <String> -Name <String> [-WaitTimer <Int32>]
 -Reviewers <Array> [-PreventSelfReview] [-DeploymentBranchPolicy <String>] [-Context <Object>]
 [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

Create or update an environment with protection rules, such as required reviewers. For more information about environment protection rules, see "Environments."

To create or update name patterns that branches must match in order to deploy to this environment, see "Deployment branch policies."

To create or update secrets for an environment, see "GitHub Actions secrets."

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

EXAMPLES

EXAMPLE 1

$params = @{
    Owner                  = "my-org"
    Repository             = "my-repo"
    Name                   = "staging"
    WaitTimer              = 30
    Reviewers              = @{ type = $user.Type; id = $user.id }, @{ type = 'team'; id = $team.DatabaseID }
    DeploymentBranchPolicy = 'CustomBranchPolicies'
}
Set-GitHubEnvironment @params

Output:

id                       : 5944178128
node_id                  : EN_kwDOOJqfM88AAAABYkz10A
name                     : test
url                      : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test
html_url                 : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test
created_at               : 3/16/2025 11:17:52 PM
updated_at               : 3/16/2025 11:17:52 PM
can_admins_bypass        : True
protection_rules         : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False;
                           reviewers=System.Object[]},@{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100},
                           @{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}}
deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True}

Creates or updates the "staging" environment with a 30-minute wait timer.

PARAMETERS

-Owner

The name of the organization.

Type: String
Parameter Sets: (All)
Aliases: Organization, User

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Repository

The name of the Repository.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Name

The name of the environment.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-WaitTimer

The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days).

Type: Int32
Parameter Sets: (All)
Aliases: wait_timer

Required: False
Position: Named
Default value: 0
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Reviewers

The people or teams that may review jobs that reference the environment. Must be an object with the following properties: - ID: The ID of the user or team. - Type: The type of reviewer. Can be either 'User' or 'Team'. Example: $Reviewers = @( @{ ID = 123456789; Type = 'User' }, @{ ID = 987654321; Type = 'Team' } )

Type: Array
Parameter Sets: WithReviewers
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-PreventSelfReview

Whether or not a user who created the job is prevented from approving their own job.

Type: SwitchParameter
Parameter Sets: WithReviewers
Aliases: prevent_self_review

Required: False
Position: Named
Default value: False
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-DeploymentBranchPolicy

The type of deployment branch policy for this environment.

Type: String
Parameter Sets: (All)
Aliases: deployment_branch_policy

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Context

The context to run the command in. Used to get the details for the API call. Can be either a string or a GitHubContext object.

Type: Object
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-GitHubContext)
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

GitHubEnvironment

NOTES

Returns the response object from the GitHub API call.

https://psmodule.io/GitHub/Functions/Environments/Set-GitHubEnvironment/

[Create or update an environment](https://docs.github.com/rest/deployments/environments#create-or-update-an-environment)