Hi Team,
I have a requirement where I need to update octopus variable set values.
Am using below script to replace the values of the variables.
##########################################################
$systemVariables = Invoke-RestMethod -Method get -Uri “$OctoURL/api/Spaces-1/variables/variableset-LibraryVariableSets-466” -Headers @{“X-Octopus-ApiKey” = $ApiKey}
function ReplacetheValue{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
$Variabletoreplace,
[Parameter(Mandatory=$true)]
$NewValue
)
Invoke-RestMethod -Method put -Uri “$OctoURL/api/Spaces-1/variables/variableset-LibraryVariableSets-466” -Body ($systemVariables | ConvertTo-Json -Depth 5)-Headers @{“X-Octopus-ApiKey” = $ApiKey}
}
ReplacetheValue -Variabletoreplace “$EachComponent.$Env_Name.$Lab_Name” -NewValue $version
##################################################
I am passing the values to both the parameters.
It works most of the time, but recently we have been getting lot of issue/ errors as below:
“System.Net.WebException: The remote server returned an error: (400) Bad Request.”
Where after getting this error, I have modified the script to retry couple of time, but it is of no use
for each try I am getting the same error again and again. & value in not replaced with new value in octopus variable set.
Can you please help me out to resolve this issue, as it is causing a lot of failures and leading to inconsistent data being available in library variable set.