Update variable in massive redeployment of latest release to new target machines

Hi guys,

We’re planning the migration of around 100 web applications to new target machines. We’re using a script which will create triggers to all project and trigger deploy to a new healthy machine. This script we used in the past, (thanks to Octopus guys to help me out last time to create it) and it worked like a charm.

$dashboard = .\Octo.exe list-projects --APIkey $apikey --server $octopusURI | Select-Object -Skip 6 
$projects = $dashboard.Substring(3) -replace "\(ID.*\)",''
Add-Type -Path 'Octopus.Client.dll' 

$triggerEnvironment = "Production" 
$triggerRole = "Webserver-Internal" 
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$environment = $repository.Environments.FindByName($triggerEnvironment)

$triggerFilter = New-Object Octopus.Client.Model.Triggers.MachineFilterResource
$triggerFilter.EnvironmentIds.Add($environment.Id)
$triggerFilter.Roles.Add($triggerRole)
$triggerFilter.EventGroups.Add("MachineAvailableForDeployment")

$triggerAction = New-Object Octopus.Client.Model.Triggers.AutoDeployActionResource
$triggerAction.ShouldRedeployWhenMachineHasBeenDeployedTo = $false
$projects = $repository.Projects.GetAll()
foreach ($project in $projects) {
    $repository.ProjectTriggers.CreateOrModify($project, "Automatically deploy to $triggerRole", $triggerFilter, 
$triggerAction)
}

Now, in production, it’s different as we defined a global variable which assigns port 8080 to a web application during deployment (don’t ask me why :)). Now, we have all the resources to use port 80 and plan to change value and redeploy to new target machines only. Current prod servers must be untouched, so we’ll add only specific target machines in scope for port 80.

How we could redeploy latest releases (around 100 web apps) to a new target machine and at the same time update global variable value and use it?

Thank you in advance,
Branko

Hi Branko,

Thanks for getting in touch! I’m sorry for the delay in getting back to you here. I have some ideas which could help you achieve this.

First, I believe the best thing to do would be to create a new target role to identify exactly which targets need to receive this deployment.

The next part is a bit harder, using a new value on already created releases. This would involve updating the release snapshot for each of these deployments after changing the variable value. Alternatively, changing the values and creating a new release to deploy.

You would need to decide if you want to update the snapshot or create a new release. If the variable is a library set variable connected to each of these projects, it makes it easier to update the value. However, if the value is set on each project it will need to be updated at the project level for each project.

I believe the best way to do this second part is to use the API. If it’s a project level variable, use the API to update the variable then create release/update snapshot.

Does this help point you in the right direction?

Sorry again for the delay in responding.

Let me know if you would like any further advice on this, or have any questions at all.

Best regards,
Daniel

Hi Daniel,

Thank you for respond. That variable is in global variable set used by all projects and creating a new release is not an option, so updating a snapshot of each project is a right for this case.
I’ll check how to do it using API, if you have any sample for this or similar case, please post it :slight_smile:

All the best,
Branko

Hi Branko,

Thanks for getting back! Updating the variable snapshot should be as simple as sending a POST to /releases/{id}/snapshot-variables.

We have a small script in our repository for this.

In the spaces update you will need to define a spaceId if you are not running this against the default space.

Let me know if this helps. :slight_smile:

Best regards,
Daniel

Hi Daniel,

Well, it’s simple to update one project by one, but I still did’t manage to do it at once.

Kind Regards,
Branko

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