Skip to content

Commit 691cb38

Browse files
authored
Sync eng/common directory with azure-sdk-tools for PR 2596 (Azure#19997)
- Fix bug in Add-ReleaseLease helper script - Enable better local logging for handling token - Enable strict mode to help catch issues like this in the future
1 parent 2144ad4 commit 691cb38

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

eng/common/pipelines/templates/steps/retain-run.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters:
22
- name: DaysValid
3-
default: 365
3+
default: 731
44
type: number
55

66
steps:
@@ -16,7 +16,6 @@ steps:
1616
-Project $(System.TeamProject)
1717
-DefinitionId $(System.DefinitionId)
1818
-RunId $(Build.BuildId)
19-
-OwnerId Pipeline
20-
-DaysValid ${{parameters.DaysValid}}
19+
-DaysValid ${{ parameters.DaysValid }}
2120
-AccessToken $env:SYSTEM_ACCESSTOKEN
2221
-Debug

eng/common/scripts/Add-RetentionLease.ps1

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,33 @@ param(
1212
[Parameter(Mandatory = $true)]
1313
[int]$RunId,
1414

15-
[Parameter(Mandatory = $true)]
16-
[string]$OwnerId,
17-
1815
[Parameter(Mandatory = $true)]
1916
[int]$DaysValid,
2017

21-
[Parameter(Mandatory = $true)]
22-
[string]$AccessToken
18+
[Parameter(Mandatory = $false)]
19+
[string]$OwnerId = "azure-sdk-pipeline-automation",
20+
21+
[Parameter(Mandatory = $false)]
22+
[string]$AccessToken = $env:DEVOPS_PAT
2323
)
2424

25+
Set-StrictMode -Version 3
26+
27+
. (Join-Path $PSScriptRoot common.ps1)
28+
2529
$unencodedAuthToken = "nobody:$AccessToken"
2630
$unencodedAuthTokenBytes = [System.Text.Encoding]::UTF8.GetBytes($unencodedAuthToken)
2731
$encodedAuthToken = [System.Convert]::ToBase64String($unencodedAuthTokenBytes)
2832

29-
# We are doing this here so that there is zero chance that this token is emitted in Azure Pipelines
30-
# build logs. Azure Pipelines will see this text and register the secret as a value it should *** out
31-
# before being transmitted to the server (and shown in logs). It means if the value is accidentally
32-
# leaked anywhere else that it won't be visible. The downside is that when the script is executed
33-
# on a local development box, it will be visible.
34-
Write-Host "##vso[task.setvariable variable=_throwawayencodedaccesstoken;issecret=true;]$($encodedAuthToken)"
33+
if ($isDevOpsRun) {
34+
# We are doing this here so that there is zero chance that this token is emitted in Azure Pipelines
35+
# build logs. Azure Pipelines will see this text and register the secret as a value it should *** out
36+
# before being transmitted to the server (and shown in logs). It means if the value is accidentally
37+
# leaked anywhere else that it won't be visible. The downside is that when the script is executed
38+
# on a local development box, it will be visible.
39+
Write-Host "##vso[task.setvariable variable=_throwawayencodedaccesstoken;issecret=true;]$($encodedAuthToken)"
40+
}
3541

36-
. (Join-Path $PSScriptRoot common.ps1)
3742

3843
LogDebug "Checking for existing leases on run: $RunId"
3944
$existingLeases = Get-RetentionLeases -Organization $Organization -Project $Project -DefinitionId $DefinitionId -RunId $RunId -OwnerId $OwnerId -Base64EncodedAuthToken $encodedAuthToken

eng/common/scripts/Invoke-DevOpsAPI.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function Add-RetentionLease {
137137
$RunId,
138138
$OwnerId,
139139
$DaysValid,
140-
$Base64AuthToken
140+
$Base64EncodedAuthToken
141141
)
142142

143143
$parameter = @{}

0 commit comments

Comments
 (0)