In my system I have many different applications, say APP1, APP2, APP3, APP4, APP5. Each has a role on the machine.
There are many different environment configurations. The applications may be on a single machine or on multiple machines in any combination. Not all apps are necessarily in all environments.
In my deployment process I need to ensure that the applications are backed up before the release is deployed. To ensure that the backup is going to be successful I need to ensure that there is sufficient space for every application on the specific machine before starting the backup process.
I can determine the space required by finding the folder size of the application itself. The issue is iterating through the applications on the server.
Is there a way that I can identify which applications are on a specific machine in the process and using Powershell iterate through those roles, querying the relevant folder for its size and adding it to a running total?
Hi, Thanks for getting in touch! My understanding of your situation is that you would like to be able to check from a list of known roles if it is currently being deployed to on a specific machine during your deployment.
One option which comes to mind could be to use the
Octopus.Machine.Roles which will return a
list of roles applied to a machine. You could then use
Octopus.Machine.Id to check if that happens to be this machine.
There are also many other Octpus System Variables which you can reference in your deployment. Our blog post on fun with output variables has some examples of how to reference these Octopus System Variables. Perhaps there are other ways to achieve this task but I’m interested in knowing if this has been helpful for you.
Thanks for your support.
I think you have a grasp of what I am trying to achieve.
I basically need to run a script on each machine in the environment, therefore I think I need to create a step with every role associated with it.
That step then enumerates through every role on the machine (which should be caught by the step as it has the role on it) run the powershell script:
$machineRoles = $OctopusParameters['Octopus.Machine.Roles']
$backupSpaceRequired = 0
foreach ($role in $machineRoles.Split(','))
#Calculate backup space for the role
#Add that value to the total
#Calculate remaining space (plus a margin)
#check and return
If ($spaceAvailable > $backupSpaceRequired)
Write-Host "Sufficient space for backup"
# not enough space
Write-Error "Not enough space for backup" -ErrorAction Stop
The Write-Error statement should cause the step to fail and therefore no further steps will continue.
Am I right in my thoughts?
Thanks for keeping in touch! I ran some testing based on the script you provided and it looks like this approach is going to work for you.
I found that calling
$machineRoles = $OctopusParameters['Octopus.Machine.Roles'] indeed returns each Role applied to this machine so your approach looks good.
I look forward to hearing how this goes for you, please feel free to keep in touch if you have any questions!
It does indeed appear to be working the way I expected it to.