pipeline file changes

This commit is contained in:
Brett Hewitson 2022-12-29 14:29:54 +10:00
parent be2730ea23
commit d394c57a10
2 changed files with 99 additions and 16 deletions

View file

@ -12,33 +12,35 @@ steps:
inputs:
targetType: inline
script: |
[string]$repositoryUrl = $env:SYSTEM_COLLECTIONURI
[string]$repositoryName = $env:SYSTEM_TEAMPROJECT
[string]$definitionId = $env:SYSTEM_DEFINITIONID
[string]$CollectionUri = $env:SYSTEM_COLLECTIONURI
[string]$ProjectName = $env:SYSTEM_TEAMPROJECT
[string]$DefinitionId = $env:SYSTEM_DEFINITIONID
[string]$variableName = '${{parameters.VariableName}}'
[string]$variableValue = '${{parameters.VariableValue}}'
[string]$accessToken = $env:SYSTEM_ACCESSTOKEN
if ($repositoryUrl.EndsWith('/')) {
$repositoryUrl = $repositoryUrl.TrimEnd('/')
if ($CollectionUri.EndsWith('/')) {
$CollectionUri = $CollectionUri.TrimEnd('/')
}
$headers = @{
'Authorization' = "Bearer $accessToken"
'Authorization' = "Bearer $AccessToken"
}
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
# Get an overview of the build definition
$definitionUrl = "$repositoryUrl/$repositoryName/_apis/build/Definitions/$($definitionId)?api-version=5.0"
$definitionUrl = "$CollectionUri/$repositoryName/_apis/build/Definitions/$($definitionId)?api-version=5.0"
$definitionResponse = Invoke-RestMethod -Method Get -Uri $definitionUrl -Headers $headers -UseBasicParsing
# If the build has the variable, update it.
if ($definitionResponse.variables.$variableName) {
$oldValue = $definitionResponse.variables.$variableName.value
$definitionResponse.variables.$variableName.value = $variableValue
if ($definitionResponse.variables.$VariableName) {
$oldValue = $definitionResponse.variables.$variableName.value
$definitionResponse.variables.$variableName.value = $VariableValue
Write-Output -InputObject "Updating $variableName from $($oldValue) to $($variableValue)..."
Write-Output -InputObject "Updating $variableName from $($oldValue) to $($variableValue)..."
$body = ConvertTo-Json -InputObject $definitionResponse -Depth 100 -Compress
$response = Invoke-RestMethod -Method Put -Uri $definitionUrl -Headers $headers -ContentType 'application/json' -Body $body -UseBasicParsing
$body = ConvertTo-Json -InputObject $definitionResponse -Depth 100 -Compress
$response = Invoke-RestMethod -Method Put -Uri $definitionUrl -Headers $headers -ContentType 'application/json' -Body $body -UseBasicParsing
}
pwsh: true