Passing variables between Pre-Deploy and Deploy scripts

In our “Deploy NuGet Step”, we have custom Pre-Deployment and Deployment scripts, and have a need to pass parameters between them. Since they are in the same “Step”, we can’t use Step Output variables. Is there any way to accomplish this? Can we use Global Variables, or update the variables that are passed to the Step somehow?

Here is a sample:
Pre-Deploy:
$osFamily = 4
$latestVersion = Get-AzureOSVersion | where {$.Family -eq $osFamily -and $.IsDefault -eq 1}
$osLabel = $latestVersion.FamilyLabel
$osVersion = $latestVersion.Label

Write-Host "Azure Pre-Deployment Environment"
Write-Host "============================"
Write-Host "osFamily : $osLabel"
Write-Host “osVersion : $osVersion”

Deploy:

This is where we want to use the variables from the Pre-Deploy step

Write-Host "Azure Deployment Environment"
Write-Host "============================"
Write-Host "osFamily : $osLabel"
Write-Host “osVersion : $osVersion”

Thanks, Simon.

Hi Simon,

Thanks for getting in touch!
In your first PowerShell script you can set variables that will then be available in your second PowerShell script like so:
Set-OctopusVariable -name "osFamily" -value $osFamily
Then you just have to call $osFamily in your deploy.ps1

Hope that helps!

Vanessa

Great, thanks Vanessa!

Will this work across different steps in the same project too ?

Hi Timothy,

Yes, but as an output variable.

Hope that helps!
Vanessa