diff --git a/eng/common/pipelines/templates/steps/login-to-github.yml b/eng/common/pipelines/templates/steps/login-to-github.yml index 3df66925da26..91327fcbb123 100644 --- a/eng/common/pipelines/templates/steps/login-to-github.yml +++ b/eng/common/pipelines/templates/steps/login-to-github.yml @@ -8,6 +8,9 @@ parameters: - name: VariableNamePrefix type: string default: GH_TOKEN +- name: ExportAsOutputVariable + type: boolean + default: false - name: ScriptDirectory default: eng/common/scripts @@ -20,6 +23,6 @@ steps: scriptLocation: scriptPath scriptPath: ${{ parameters.ScriptDirectory }}/login-to-github.ps1 arguments: > - -InstallationTokenOwners '${{ join(''',''', parameters.TokenOwners) }}' - -VariableNamePrefix '${{ parameters.VariableNamePrefix }}' - \ No newline at end of file + -InstallationTokenOwners '${{ join(''',''', parameters.TokenOwners) }}' + -VariableNamePrefix '${{ parameters.VariableNamePrefix }}' + -ExportAsOutputVariable:$${{ parameters.ExportAsOutputVariable }} \ No newline at end of file diff --git a/eng/common/scripts/login-to-github.ps1 b/eng/common/scripts/login-to-github.ps1 index 9a1a5bbeb5ea..c0b050f27353 100644 --- a/eng/common/scripts/login-to-github.ps1 +++ b/eng/common/scripts/login-to-github.ps1 @@ -22,6 +22,10 @@ Prefix for the exported variable name (default: GH_TOKEN). With a single owner, exports as GH_TOKEN. With multiple owners, exports as GH_TOKEN_. +.PARAMETER ExportAsOutputVariable + When set in Azure DevOps, also exports the variable as an output variable + (##vso[task.setvariable ...;isOutput=true]) for downstream jobs/stages. + .OUTPUTS Sets environment variables in the current process and exports them to the CI system: - Azure DevOps: sets secret pipeline variables via ##vso logging commands @@ -34,7 +38,8 @@ param( [string] $KeyName = "azure-sdk-automation", [string] $GitHubAppId = '1086291', # Azure SDK Automation App ID [string[]] $InstallationTokenOwners = @("Azure"), - [string] $VariableNamePrefix = "GH_TOKEN" + [string] $VariableNamePrefix = "GH_TOKEN", + [switch] $ExportAsOutputVariable ) $ErrorActionPreference = 'Stop' @@ -239,6 +244,11 @@ function Invoke-LoginToGitHub { if ($null -ne $env:SYSTEM_TEAMPROJECTID) { Write-Host "##vso[task.setvariable variable=$variableName;issecret=true]$installationToken" Write-Host "Azure DevOps variable '$variableName' has been set (secret)." + + if ($ExportAsOutputVariable) { + Write-Host "##vso[task.setvariable variable=$variableName;issecret=true;isOutput=true]$installationToken" + Write-Host "Azure DevOps output variable '$variableName' has been set (secret)." + } } # GitHub Actions: mask the token and export to GITHUB_ENV