Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eng/common/pipelines/templates/steps/login-to-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ parameters:
- name: VariableNamePrefix
type: string
default: GH_TOKEN
- name: AlwaysUseOwnerSuffix
type: boolean
default: false
- name: ExportAsOutputVariable
type: boolean
default: false
Expand All @@ -25,4 +28,5 @@ steps:
arguments: >
-InstallationTokenOwners '${{ join(''',''', parameters.TokenOwners) }}'
-VariableNamePrefix '${{ parameters.VariableNamePrefix }}'
-AlwaysUseOwnerSuffix:$${{ parameters.AlwaysUseOwnerSuffix }}
-ExportAsOutputVariable:$${{ parameters.ExportAsOutputVariable }}
6 changes: 5 additions & 1 deletion eng/common/scripts/login-to-github.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
Prefix for the exported variable name (default: GH_TOKEN).
With a single owner, exports as GH_TOKEN. With multiple owners, exports as GH_TOKEN_<Owner>.

.PARAMETER AlwaysUseOwnerSuffix
Export tokens as <VariableNamePrefix>_<Owner> even when only one owner is requested.

Comment on lines 22 to +27
.PARAMETER ExportAsOutputVariable
When set in Azure DevOps, also exports the variable as an output variable
(##vso[task.setvariable ...;isOutput=true]) for downstream jobs/stages.
Expand All @@ -39,6 +42,7 @@ param(
[string] $GitHubAppId = '1086291', # Azure SDK Automation App ID
[string[]] $InstallationTokenOwners = @("Azure"),
[string] $VariableNamePrefix = "GH_TOKEN",
[switch] $AlwaysUseOwnerSuffix,
[switch] $ExportAsOutputVariable
)

Expand Down Expand Up @@ -231,7 +235,7 @@ function Invoke-LoginToGitHub {
$installationToken = New-GitHubInstallationToken -Jwt $jwt -InstallationId $installationId -ApiBase $GitHubApiBaseUrl -ApiVersion $GitHubApiVersion

$variableName = $VariableNamePrefix
if ($InstallationTokenOwners.Count -gt 1) {
if ($AlwaysUseOwnerSuffix -or $InstallationTokenOwners.Count -gt 1) {
$variableName = $VariableNamePrefix + "_" + $normalizedOwner
}

Expand Down