Skip some specific Project variables from updating Octopus Release Variables using Script

resolved
server
usability
support
known
(Santoshuponi) #1

Hi Team,

I found below powershell script to update release snapshot (For all variables )

======================================================================
Add-Type -Path ‘C:\PathTo\Octopus.Client.dll’

$apikey = ‘API-1234’ # Get this from your profile
$octopusURI = ‘http://YOUR_SERVER’ # Your Octopus Server address

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$projectName = “Testing testing 123”
$project = $repository.Projects.FindByName($projectName);
if (!$project) {
Write-Host(“Failed to find project with name $($projectName).”)
Exit
}

$releaseVersion = “0.0.2”
$release = $repository.Projects.GetReleaseByVersion($project, $releaseVersion);
if (!$release) {
Write-Host(“Failed to find release with version $($releaseVersion).”)
Exit
}

Update snapshot

$repository.Releases.SnapshotVariables($release)
Write-Host(“Success”)

======================================================================

I have scenario where i want to exclude only Project -> variables -> xzy ,
is there any way to achieve this by updating script above !!!

For example below highlighted variable has to be excluded from Update variable.

Thanks
Santhosh Shet

(Paul Calvert) #3

Hi Santhosh,

Thanks for getting in touch!

Unfortunately, the update snapshot function is all or nothing. The only way I can think of achieving what you want would be to have a script that changes that single variable to the value you want, then running the update variable snapshot script, then amending the variable back to what it was.

Regards,
Paul

(Santoshuponi) #4

Hi Paul,

Thanks for your quick help, I understood that there is no option to customize "Update Variable " function to as per our need.

Thanks
Santhosh Shet

1 Like
(Santoshuponi) #5

Hi Paul,

I want achieve to keep that specific project variable unchanged even after “Update variable” , so for that i need a script to get the project variable (Which i want to exclude from Update variables , i.e old value before updating snap shoot) and amending back after “Update variable”.

Can you please help me in script !!

Thanks
Santhosh Shet

(Paul Calvert) #6

Hi Santhosh,

I would need to have a better understanding of what your use case if for this scenario first.

It sounds like you’re updating a bunch of project variables, then want to update a release with these variable changes, except for the change to variable ‘check’.
This isn’t possible in single script.

The only way I could see to achieve this would be to break it down into two stages.
In the first stage, you amend all of the project variables that you need to change, except for variable ‘check’. You then run the variable snapshot script for your release.
It now has all variable changes applied except for ‘check’.

Stage two would be to then amend the variable ‘check’ to whatever value you want it to be, but without running the variable snapshot script.

What I don’t really understand is why you’re needing to do this in the first place?
Is this a one-off run to fix some variables in a specific release or is this part of your regular deployment process?

If you need different releases to have different values for the variable ‘check’ as ongoing situation, then perhaps it may be easier to apply some form of scoping to this variable, maybe making use of release channels or environments to separate when the different ‘check’ values are applied.

Regards,
Paul

(Santoshuponi) #7

Hi Paul,

Thanks for your help ,
I understand that it need 2 phase to achieve , Do you have any sample powershell scripts to ( ""amend all of the project variables that you need to change, except for variable ‘check’ “”. and ““Stage two would be to then amend the variable ‘check’ to whatever value you want it to be, but without running the variable snapshot script.”” ) serve the same so that i can modify as per my request .

Thanks
Santhosh Shet

(Paul Calvert) #8

Hi Santhosh,

All of our script samples can be found here: https://github.com/OctopusDeploy/OctopusDeploy-Api

This one may be useful.

(system) closed #9

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.