Skip to content

Set-GitHubVariable

SYNOPSIS

Creates or updates a GitHub Actions variable at the organization, repository, or environment level.

SYNTAX

Environment

Set-GitHubVariable -Owner <String> -Repository <String> -Environment <String> -Name <String> [-Value <String>]
 [-Context <Object>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

Repository

Set-GitHubVariable -Owner <String> -Repository <String> -Name <String> [-Value <String>] [-Context <Object>]
 [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

Organization

Set-GitHubVariable -Owner <String> -Name <String> [-Value <String>] [-Visibility <String>]
 [-SelectedRepositories <UInt64[]>] [-Context <Object>] [-ProgressAction <ActionPreference>] [-WhatIf]
 [-Confirm] [<CommonParameters>]

DESCRIPTION

This function checks if a GitHub Actions variable exists at the specified level (organization, repository, or environment). If the variable exists, it updates it with the new value. If it does not exist, it creates a new variable.

  • Organization-level variables require the admin:org scope for OAuth tokens and personal access tokens (classic). If the repository is private, the repo scope is also required.
  • Repository-level variables require the repo scope.
  • Environment-level variables require collaborator access to the repository.

EXAMPLES

EXAMPLE 1

Set-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext

Creates or updates a repository variable named HOST_NAME with the value github.com in the specified repository.

EXAMPLE 2

Set-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Visibility 'all' -Context $GitHubContext

Creates or updates an organization variable named HOST_NAME with the value github.com and makes it available to all repositories in the organization.

EXAMPLE 3

Set-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext

Creates or updates an environment variable named HOST_NAME with the value github.com in the specified environment.

PARAMETERS

-Owner

The account owner of the repository. The name is not case sensitive.

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

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

-Repository

The name of the repository. The name is not case sensitive.

Type: String
Parameter Sets: Environment, Repository
Aliases:

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

-Environment

The name of the repository environment.

Type: String
Parameter Sets: Environment
Aliases:

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

-Name

The name of the variable.

Type: String
Parameter Sets: (All)
Aliases:

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

-Value

The value of the variable.

Type: String
Parameter Sets: (All)
Aliases:

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

-Visibility

The visibility of the variable when updating an organization variable. Can be private, selected, or all.

Type: String
Parameter Sets: Organization
Aliases:

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

-SelectedRepositories

The IDs of the repositories to which the variable is available. Used only when the -Visibility parameter is set to selected.

Type: UInt64[]
Parameter Sets: Organization
Aliases:

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

-Context

The context to run the command in. 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

GitHubVariable

NOTES

Returns an GitHubVariable object containing details about the environment variable, including its name, value, associated repository, and environment details.

https://psmodule.io/GitHub/Functions/Variables/Set-GitHubVariable/