Skip to content

Commit 8b8a346

Browse files
authored
Use Az.KeyVault to get github PAT instead of pipeline variable (#22912)
* Use Az.KeyVault to get github PAT instead of pipeline variable * Use Az.KeyVault to get github PAT instead of pipeline variable
1 parent 22cbbd1 commit 8b8a346

File tree

10 files changed

+98
-15
lines changed

10 files changed

+98
-15
lines changed

.azure-pipelines/code-gen.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Variable 'BotAccessToken' was defined in the Variables tab
21
# Multi-job configuration must be converted to matrix strategy: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml#multi-job-configuration
32
parameters:
43
- name: TargetBranch
@@ -31,7 +30,7 @@ jobs:
3130
inputs:
3231
command: custom
3332
verbose: false
34-
customCommand: install -g autorest@latest
33+
customCommand: install -g autorest@latest
3534
- task: PowerShell@2
3635
displayName: Generate
3736
inputs:
@@ -46,6 +45,16 @@ jobs:
4645
}
4746
workingDirectory: src/${{ parameters.ServiceName }}
4847

48+
- task: AzurePowerShell@5
49+
inputs:
50+
azureSubscription: '$(AzureSubscription)'
51+
ScriptType: 'InlineScript'
52+
Inline: |
53+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
54+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
55+
azurePowerShellVersion: 'LatestVersion'
56+
displayName: Get Github PAT from Key Vault
57+
4958
- task: PowerShell@2
5059
displayName: Build
5160
inputs:
@@ -92,7 +101,7 @@ jobs:
92101
git add ./src;
93102
git add tools/CreateMappings_rules.json;
94103
git commit -m "Move ${{ parameters.ServiceName }} to ${{ parameters.TargetBranch }}";
95-
git remote set-url origin https://azure-powershell-bot:$(BotAccessToken)@github.com/Azure/azure-powershell.git;
104+
git remote set-url origin https://azure-powershell-bot:$(GithubToken)@github.com/Azure/azure-powershell.git;
96105
git push origin codegen/${{ parameters.ServiceName }} --force;
97106
displayName: Create codegen/${{ parameters.ServiceName }} branch
98107
- pwsh: |
@@ -102,5 +111,5 @@ jobs:
102111
$SourceBranch = "$(Build.SourceBranch)"
103112
$SourceBranch = $BaseBranch.Replace("refs/heads/", "")
104113
$Description = "Migrate ${{ parameters.ServiceName }} from $SourceBranch to ${{ parameters.TargetBranch }}"
105-
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(BotAccessToken) -Description $Description
114+
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(GithubToken) -Description $Description
106115
displayName: Create PR to main branch

.azure-pipelines/code-sign.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@ jobs:
1212
variables:
1313
LocalRepoName: 'LocalRepo'
1414
steps:
15+
- task: AzurePowerShell@5
16+
inputs:
17+
azureSubscription: '$(AzureSubscription)'
18+
ScriptType: 'InlineScript'
19+
Inline: |
20+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
21+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
22+
azurePowerShellVersion: 'LatestVersion'
23+
displayName: Get Github PAT from Key Vault
24+
1525
- task: PowerShell@2
1626
displayName: checkout OOBbranch
1727
inputs:
1828
targetType: 'inline'
1929
script: |
2030
if ('${{ parameters.OOBBranch }}' -ne 'none') {
21-
git remote set-url origin https://azure-powershell-bot:$Token@github.com/Azure/azure-powershell.git;
31+
git remote set-url origin https://azure-powershell-bot:$GithubToken@github.com/Azure/azure-powershell.git;
2232
git fetch origin
2333
git checkout -b ${{ parameters.OOBBranch }} origin/${{ parameters.OOBBranch }}
2434
}

.azure-pipelines/security-tools.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ jobs:
3838
inputs:
3939
targetType: inline
4040
script: npm install autorest@latest;$env:NODE_OPTIONS="--max-old-space-size=65536"
41+
42+
- task: AzurePowerShell@5
43+
inputs:
44+
azureSubscription: '$(AzureSubscription)'
45+
ScriptType: 'InlineScript'
46+
Inline: |
47+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
48+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
49+
azurePowerShellVersion: 'LatestVersion'
50+
displayName: Get Github PAT from Key Vault
4151
- task: PowerShell@2
4252
displayName: Build
4353
inputs:
4454
targetType: inline
4555
script: dotnet msbuild build.proj /t:"Build;GenerateHelp" /p:"PullRequestNumber=$(System.PullRequest.PullRequestNumber);IsSecurityCheck=true"
4656
env:
47-
OCTOKITPAT: $(OCTOKITPAT)
57+
OCTOKITPAT: $(GithubToken)
4858
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@3
4959
displayName: Run CredScan
5060
condition: in(variables['system.pullRequest.targetBranch'], 'generation', 'main')

.azure-pipelines/sync-MSdoc.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ trigger:
1515
variables:
1616
TargetedRepo: azure-docs-powershell
1717
TargetedBranchName: sync-upcoming-breaking-changes
18-
GithubToken: $(GITHUB_TOKEN)
1918

2019
jobs:
2120
- job: Sync
@@ -27,6 +26,15 @@ jobs:
2726
BranchName: ${{ variables.TargetedBranchName }}
2827

2928
steps:
29+
- task: AzurePowerShell@5
30+
inputs:
31+
azureSubscription: '$(AzureSubscription)'
32+
ScriptType: 'InlineScript'
33+
Inline: |
34+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
35+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
36+
azurePowerShellVersion: 'LatestVersion'
37+
displayName: Get Github PAT from Key Vault
3038
- task: PowerShell@2
3139
displayName: Sync branch
3240
inputs:

.azure-pipelines/sync-tools-folder.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ trigger:
2929

3030
variables:
3131
GenerationBranchName: generation
32-
GithubToken: $(GITHUB_TOKEN)
3332

3433
jobs:
3534
- job: Sync
@@ -41,6 +40,15 @@ jobs:
4140
BranchName: ${{ variables.GenerationBranchName }}
4241

4342
steps:
43+
- task: AzurePowerShell@5
44+
inputs:
45+
azureSubscription: '$(AzureSubscription)'
46+
ScriptType: 'InlineScript'
47+
Inline: |
48+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
49+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
50+
azurePowerShellVersion: 'LatestVersion'
51+
displayName: Get Github PAT from Key Vault
4452
- task: PowerShell@2
4553
displayName: Sync branch
4654
inputs:

.azure-pipelines/test-coverage.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ jobs:
123123
filePath: ./tools/TestFx/Coverage/SaveTestCoverageResult.ps1
124124
arguments: CITest $(KustoTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion)
125125

126+
- task: AzurePowerShell@5
127+
inputs:
128+
azureSubscription: '$(AzureSubscription)'
129+
ScriptType: 'InlineScript'
130+
Inline: |
131+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
132+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
133+
azurePowerShellVersion: 'LatestVersion'
134+
displayName: Get Github PAT from Key Vault
135+
126136
- task: PowerShell@2
127137
displayName: Update Test Coverage Baseline
128138
condition: succeeded()
@@ -138,14 +148,14 @@ jobs:
138148
git config user.name "azure-powershell-bot"
139149
git add $blCsv
140150
git commit -m "Update with the latest test coverage data"
141-
git remote set-url origin https://azure-powershell-bot:$(BotAccessToken)@github.com/Azure/azure-powershell.git
151+
git remote set-url origin https://azure-powershell-bot:$(GithubToken)@github.com/Azure/azure-powershell.git
142152
git push origin testcoverage-baseline --force
143153
144154
$title = "Update test coverage baseline"
145155
$headBranch = "testcoverage-baseline"
146156
$targetBranch = "main"
147157
$description = "Update with the latest test coverage baseline data"
148-
./tools/Github/CreatePR.ps1 -Title $title -HeadBranch $headBranch -BaseBranch $targetBranch -BotAccessToken $(BotAccessToken) -Description $description
158+
./tools/Github/CreatePR.ps1 -Title $title -HeadBranch $headBranch -BaseBranch $targetBranch -BotAccessToken $(GithubToken) -Description $description
149159
150160
- task: PublishPipelineArtifact@1
151161
displayName: Publish Test Coverage Result

.azure-pipelines/util/analyze-steps.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ steps:
2828
tar -xvzf "Az-Cmdlets-latest/Az-Cmdlets-latest.tar.gz" -C "Az-Cmdlets-latest"
2929
. Az-Cmdlets-latest/InstallModule.ps1
3030
pwsh: true
31+
32+
- task: AzurePowerShell@5
33+
inputs:
34+
azureSubscription: '$(AzureSubscription)'
35+
ScriptType: 'InlineScript'
36+
Inline: |
37+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
38+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
39+
azurePowerShellVersion: 'LatestVersion'
40+
displayName: Get Github PAT from Key Vault
3141

3242
- task: DotNetCoreCLI@2
3343
displayName: 'Generate Help'
@@ -36,7 +46,7 @@ steps:
3646
custom: msbuild
3747
arguments: 'build.proj /t:GenerateHelp /p:Configuration=${{ parameters.configuration }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
3848
env:
39-
OCTOKITPAT: $(OCTOKITPAT)
49+
OCTOKITPAT: $(GithubToken)
4050
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
4151

4252
- task: DotNetCoreCLI@2
@@ -46,7 +56,7 @@ steps:
4656
custom: msbuild
4757
arguments: 'build.proj /t:StaticAnalysis /p:Configuration=${{ parameters.configuration }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
4858
env:
49-
OCTOKITPAT: $(OCTOKITPAT)
59+
OCTOKITPAT: $(GithubToken)
5060
IsGenerateBased: ${{ parameters.IsGenerateBased }}
5161

5262
- template: publish-artifacts-steps.yml

.azure-pipelines/util/build-steps.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ steps:
2828
inputs:
2929
packageType: sdk
3030
version: 6.0.x
31+
- task: AzurePowerShell@5
32+
inputs:
33+
azureSubscription: '$(AzureSubscription)'
34+
ScriptType: 'InlineScript'
35+
Inline: |
36+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
37+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
38+
azurePowerShellVersion: 'LatestVersion'
39+
displayName: Get Github PAT from Key Vault
3140

3241
- task: DotNetCoreCLI@2
3342
displayName: Build
@@ -36,7 +45,7 @@ steps:
3645
custom: msbuild
3746
arguments: 'build.proj /t:Build /p:Configuration=${{ parameters.configuration }};TestFramework=${{ parameters.testFramework }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
3847
env:
39-
OCTOKITPAT: $(OCTOKITPAT)
48+
OCTOKITPAT: $(GithubToken)
4049
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
4150

4251
- task: PowerShell@2

.azure-pipelines/util/test-steps.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ steps:
1616
packageType: sdk
1717
version: 6.0.x
1818

19+
- task: AzurePowerShell@5
20+
inputs:
21+
azureSubscription: '$(AzureSubscription)'
22+
ScriptType: 'InlineScript'
23+
Inline: |
24+
$GithubToken = Get-AzKeyVaultSecret -VaultName $(KeyVaultName) -Name $(KeyVaultAccount) -AsPlainText
25+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
26+
azurePowerShellVersion: 'LatestVersion'
27+
displayName: Get Github PAT from Key Vault
28+
1929
- task: PowerShell@2
2030
displayName: Remove pre-installed Az modules
2131
inputs:
@@ -30,7 +40,7 @@ steps:
3040
custom: msbuild
3141
arguments: 'build.proj /t:${{ parameters.testTarget }} /p:Configuration=${{ parameters.configuration }};TestFramework=${{ parameters.testFramework }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
3242
env:
33-
OCTOKITPAT: $(OCTOKITPAT)
43+
OCTOKITPAT: $(GithubToken)
3444
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
3545
continueOnError: true
3646

.azure-pipelines/ux-portal.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Variable 'BotAccessToken' was defined in the Variables tab
21
# Multi-job configuration must be converted to matrix strategy: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml#multi-job-configuration
32
parameters:
43
- name: AzurePowerShellVersion

0 commit comments

Comments
 (0)