Skip to content

Commit c9ca730

Browse files
Export installationToken as output variable to allow it be used in subsequesnt steps (#47445)
Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
1 parent 2223998 commit c9ca730

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

eng/common/pipelines/templates/steps/login-to-github.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ parameters:
88
- name: VariableNamePrefix
99
type: string
1010
default: GH_TOKEN
11+
- name: ExportAsOutputVariable
12+
type: boolean
13+
default: false
1114
- name: ScriptDirectory
1215
default: eng/common/scripts
1316

@@ -20,6 +23,6 @@ steps:
2023
scriptLocation: scriptPath
2124
scriptPath: ${{ parameters.ScriptDirectory }}/login-to-github.ps1
2225
arguments: >
23-
-InstallationTokenOwners '${{ join(''',''', parameters.TokenOwners) }}'
24-
-VariableNamePrefix '${{ parameters.VariableNamePrefix }}'
25-
26+
-InstallationTokenOwners '${{ join(''',''', parameters.TokenOwners) }}'
27+
-VariableNamePrefix '${{ parameters.VariableNamePrefix }}'
28+
-ExportAsOutputVariable:$${{ parameters.ExportAsOutputVariable }}

eng/common/scripts/login-to-github.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
Prefix for the exported variable name (default: GH_TOKEN).
2323
With a single owner, exports as GH_TOKEN. With multiple owners, exports as GH_TOKEN_<Owner>.
2424
25+
.PARAMETER ExportAsOutputVariable
26+
When set in Azure DevOps, also exports the variable as an output variable
27+
(##vso[task.setvariable ...;isOutput=true]) for downstream jobs/stages.
28+
2529
.OUTPUTS
2630
Sets environment variables in the current process and exports them to the CI system:
2731
- Azure DevOps: sets secret pipeline variables via ##vso logging commands
@@ -34,7 +38,8 @@ param(
3438
[string] $KeyName = "azure-sdk-automation",
3539
[string] $GitHubAppId = '1086291', # Azure SDK Automation App ID
3640
[string[]] $InstallationTokenOwners = @("Azure"),
37-
[string] $VariableNamePrefix = "GH_TOKEN"
41+
[string] $VariableNamePrefix = "GH_TOKEN",
42+
[switch] $ExportAsOutputVariable
3843
)
3944

4045
$ErrorActionPreference = 'Stop'
@@ -239,6 +244,11 @@ function Invoke-LoginToGitHub {
239244
if ($null -ne $env:SYSTEM_TEAMPROJECTID) {
240245
Write-Host "##vso[task.setvariable variable=$variableName;issecret=true]$installationToken"
241246
Write-Host "Azure DevOps variable '$variableName' has been set (secret)."
247+
248+
if ($ExportAsOutputVariable) {
249+
Write-Host "##vso[task.setvariable variable=$variableName;issecret=true;isOutput=true]$installationToken"
250+
Write-Host "Azure DevOps output variable '$variableName' has been set (secret)."
251+
}
242252
}
243253

244254
# GitHub Actions: mask the token and export to GITHUB_ENV

0 commit comments

Comments
 (0)