mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +00:00
pipeline file changes
This commit is contained in:
parent
6d1da1270f
commit
942fdb66d3
2 changed files with 183 additions and 143 deletions
58
.azure/pipelines/update-pipeline-variable.yml
Normal file
58
.azure/pipelines/update-pipeline-variable.yml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
parameters:
|
||||
- name: VariableName
|
||||
displayName: Variable Name
|
||||
- name: VariableValue
|
||||
displayName: Variable Value
|
||||
|
||||
steps:
|
||||
- task: PowerShell@2
|
||||
displayName: Update Pipeline Variable - ${{parameters.VariableName}}
|
||||
env:
|
||||
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
|
||||
inputs:
|
||||
targetType: inline
|
||||
script: |
|
||||
[string]$repositoryUrl = $env:SYSTEM_COLLECTIONURI
|
||||
[string]$repositoryName = $env:SYSTEM_TEAMPROJECT
|
||||
[string]$definitionId = $env:SYSTEM_DEFINITIONID
|
||||
[string]$variableName = ${{parameters.VariableName}}
|
||||
[string]$variableValue = ${{parameters.VariableValue}}
|
||||
[string]$accessToken = $env:SYSTEM_ACCESSTOKEN
|
||||
[string]$debugMode = $env.SYSTEM_DEBUG
|
||||
|
||||
if ($debugMode -eq 'true') {
|
||||
Write-Host '##[section]Starting: DEBUG INFORMATION'
|
||||
|
||||
Write-Host "##[debug]repositoryUrl = $repositoryUrl"
|
||||
Write-Host "##[debug]repositoryName = $repositoryName"
|
||||
Write-Host "##[debug]definitionId = $definitionId"
|
||||
Write-Host "##[debug]variableName = $variableName"
|
||||
Write-Host "##[debug]variableValue = $variableValue"
|
||||
|
||||
Write-Host '##[section]Finishing: DEBUG INFORMATION'
|
||||
Write-Host ''
|
||||
}
|
||||
|
||||
if($repositoryUrl.EndsWith('/')) {
|
||||
$repositoryUrl = $repositoryUrl.TrimEnd('/')
|
||||
}
|
||||
|
||||
$headers = @{
|
||||
'Authorization' = "Bearer $accessToken"
|
||||
}
|
||||
|
||||
# Get an overview of the build definition
|
||||
$definitionUrl = "$repositoryUrl/$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
|
||||
|
||||
Write-Output -InputObject "Updating $variableName from $($oldValue) to $($variableValue)..."
|
||||
|
||||
$body = ConvertTo-Json -InputObject $definitionResponse -Depth 100 -Compress
|
||||
$response = Invoke-RestMethod -Method Put -Uri $definitionsUrl -Headers $headers -ContentType 'application/json' -Body $body -UseBasicParsing
|
||||
}
|
||||
pwsh: true
|
||||
Loading…
Add table
Add a link
Reference in a new issue