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
9 changes: 6 additions & 3 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: ExportAsOutputVariable
type: boolean
default: false
- name: ScriptDirectory
default: eng/common/scripts

Expand All @@ -20,6 +23,6 @@ steps:
scriptLocation: scriptPath
scriptPath: ${{ parameters.ScriptDirectory }}/login-to-github.ps1
arguments: >
-InstallationTokenOwners '${{ join(''',''', parameters.TokenOwners) }}'
-VariableNamePrefix '${{ parameters.VariableNamePrefix }}'

-InstallationTokenOwners '${{ join(''',''', parameters.TokenOwners) }}'
-VariableNamePrefix '${{ parameters.VariableNamePrefix }}'
-ExportAsOutputVariable:$${{ parameters.ExportAsOutputVariable }}
12 changes: 11 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,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_<Owner>.

.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
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down
Loading