Calculate Deployment Mode

Octopus.Script exported 2021-11-02 by BobJWalker belongs to ‘Octopus’ category.

This step uses Octopus System Variables to calculate the deployment mode.

Deployment Mode

The potential modes are:

  • Deploy: A newer version is being deployed to the target environment. For example, 2021.1.4 is being deployed to Production to replace 2021.0.5.
  • Rollback: An older version is being deployed to the target environment. For example, 2021.0.5 is being deployed to Production to replace 2021.1.4.
  • Redeploy: The same version is being deployed to the target environment. For example, 2021.1.4 is being deployed to Production which already has 2021.1.4.

Please note: This step template uses the release numbers to calculate the deployment mode. It doesn’t look at any packages.

Version Difference

After calculating the deployment mode, the step template will calculate the version difference. The potential options are:

  • Identical: No differences between the previous release and the current release were found.
  • Major: The first number (2021 in 2021.1.2.10) is different between the previous release and the current release.
  • Minor: The second number (1 in 2021.1.2.10) is different between the previous release and the current release.
  • Build: The third number (2 in 2021.1.2.10) is different between the previous release and the current release.
  • Revision: The fourth number (10 in 2021.1.2.10) is different between the previous release and the current release.

Manual or Automatic Trigger

The step template will also determine if the deployment was caused by a trigger or is a manual deployment. Potential values are True (caused by a trigger) or False (manual deployment).

Output Variables

The following output variables will be set:

  • DeploymentMode: Will either be Deploy, Rollback or Redeploy.
  • Trigger: Will either be True or False. Indicates if this deployment was caused by a trigger (scheduled or deployment target).
  • VersionChange: Will either be Identical, Major, Minor, Build, or Revision.

Variable Run Condition Output Variables

To make it easier to use, the step template will set a number of run condition output variables.

Variable Run Condition Usage

Variable Run Conditions will always be evaluated. Even if there is an error. If the run condition comes back as Truthy it will run the step.

To limit when the step runs, wrap the output variable with an if/then or unless clause:

  • Always Run: #{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}
  • Success: Only run when previous steps succeeds #{unless Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/unless}
  • Failure: Only run when previous steps fail #{if Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/if}

Hint: Replace RunOnDeploy from the above examples with one of the variables from below.

Deployment Mode Run Conditions

  • RunOnDeploy: Only run the step when the DeploymentMode is Deploy.
  • RunOnRollback: Only run the step when the DeploymentMode is Rollback.
  • RunOnRedeploy: Only run the step when the DeploymentMode is Redeploy.
  • RunOnDeployOrRollback: Only run the step when the DeploymentMode isDeploy or Rollback.
  • RunOnDeployOrRedeploy: Only run the step when the DeploymentMode isDeploy or Redeploy.
  • RunOnRedeployOrRollback: Only run the step when the DeploymentMode is Redeploy or Rollback.

Version Change Run Conditions

  • RunOnMajorVersionChange: Only run the step when the VersionChange is Major.
  • RunOnMinorVersionChange: Only run the step when the VersionChange is Minor.
  • RunOnMajorOrMinorVersionChange: Only run the step when the VersionChange is Major or Minor.
  • RunOnBuildVersionChange: Only run the step when the VersionChange is Build.
  • RunOnRevisionVersionChange: Only run the step when the VersionChange is Revision.

Usage

Important: This step template is designed for deployment processes only. Runbooks have no concept of deployments, redeployments, or rollbacks.

This step was designed to run on a worker (or the Octopus Server). It can run on targets, but the output variables will all be the same; running on targets will do nothing but waste compute cycles.

Script body

Steps based on this template will execute the following PowerShell script.

$currentReleaseNumber = $OctopusParameters["Octopus.Release.Number"]
$previousReleaseNumber = $OctopusParameters["Octopus.Release.CurrentForEnvironment.Number"]
$lastAttemptedReleaseNumber = $OctopusParameters["Octopus.Release.PreviousForEnvironment.Number"]
$stepName = $OctopusParameters["Octopus.Action.StepName"]
$triggerName = $OctopusParameters["Octopus.Deployment.Trigger.Name"]

Write-Host "The current release number is $currentReleaseNumber"
Write-Host "The last succesful release to this environment was $previousReleaseNumber"
Write-Host "The last release that was attempted on this environment was $lastAttemptedReleaseNumber"
Write-Host "The deployment name is $deploymentName"

if ($previousReleaseNumber -like "*-*")
{
	$previousReleaseNumber = $previousReleaseNumber.SubString(0, $previousReleaseNumber.IndexOf("-"))
}

if ($currentReleaseNumber -like "*-*")
{
	$currentReleaseNumber = $currentReleaseNumber.SubString(0, $currentReleaseNumber.IndexOf("-"))
}

if ($lastAttemptedReleaseNumber -like "*-*")
{
	$lastAttemptedReleaseNumber = $lastAttemptedReleaseNumber.SubString(0, $lastAttemptedReleaseNumber.IndexOf("-"))
}

Write-Host "The non-pre release tag previous version for the environment was $previousReleaseNumber"
Write-Host "The non-pre release tag current release number is $currentReleaseNumber"
Write-Host "The non-pre release tag of the last attempted version for the environment was $lastAttemptedReleaseNumber"

$currentVersion = [System.Version]$currentReleaseNumber
$previousVersion = [System.Version]$previousReleaseNumber
$lastAttemptedVersion = [System.Version]$lastAttemptedReleaseNumber

$differentVersions = $false
$versionToCompare = $previousVersion
if ($currentVersion -gt $previousVersion)
{
	Write-Host "The current release number $currentReleaseNumber is greater than the previous successful release number $previousReleaseNumber."
	if ($currentVersion -lt $lastAttemptedVersion)
    {
    	Write-Host "The current release number $currentReleaseNumber is less than the last attempted release number $lastAttemptedReleaseNumber.  Setting deployment mode to rollback."
	    $deploymentMode = "Rollback"
        $versionToCompare = $lastAttemptedVersion
    }
    else
    {
    	Write-Host "The current release number $curentReleaseNumber is greater than the last attempted release number $lastAttemptedReleaseNumber.  Setting deployment mode to deploy."
        $deploymentMode = "Deploy"
    }
}
elseif ($currentVersion -lt $previousVersion)
{
	Write-Host "The current release number $currentReleaseNumber is less than the previous successful release number $previousReleaseNumber.  Setting deployment mode to rollback."
    $deploymentMode = "Rollback"
    $differentVersions = $true
}
elseif ($currentVersion -lt $lastAttemptedVersion)
{
	Write-Host "The current release number $currentReleaseNumber is less than the last attempted release number $lastAttemptedReleaseNumber.  Setting the deployment mode to rollback."
    $deploymentMode = "Rollback"
    $differentVersions = $true
    $versionToCompare = $lastAttemptedVersion
}
else
{
	Write-Host "The current release number $currentReleaseNumber matches the previous release number $previousReleaseNumber.  Setting deployment mode to redeployment."
    $deploymentMode = "Redeploy"
}

$differenceKind = "Identical"
if ($differentVersions)
{
	if ($currentVersion.Major -ne $versionToCompare.Major)
    {
    	Write-Host "$currentReleaseNumber is a major version change from $versionToCompare"
    	$differenceKind = "Major"
    }
    elseif ($currentVersion.Minor -ne $versionToCompare.Minor)
    {
    	Write-Host "$currentReleaseNumber is a minor version change from $versionToCompare"
    	$differenceKind = "Minor"
    }
    elseif ($currentVersion.Build -ne $versionToCompare.Build)
    {
    	Write-Host "$currentReleaseNumber is a build version change from $versionToCompare"
    	$differenceKind = "Build"
    }
    elseif ($currentVersion.Revision -ne $versionToCompare.Revision)
    {
    	Write-Host "$currentReleaseNumber is a revision version change from $versionToCompare"
    	$differenceKind = "Revision"
    }
}

$trigger = $false
if ([string]::IsNullOrWhiteSpace($triggerName) -eq $false)
{
	Write-Host "This task was created by trigger $triggerName."
    $trigger = $true
}

Set-OctopusVariable -Name "DeploymentMode" -Value $deploymentMode
Set-OctopusVariable -Name "VersionChange" -Value $differenceKind
Set-OctopusVariable -Name "Trigger" -Value $trigger

Write-Highlight @"
Output Variables Created:
   	- Octopus.Action[$($stepName)].Output.DeploymentMode - Set to '$deploymentMode'
    - Octopus.Action[$($stepName)].Output.VersionChange - Set to '$differenceKind'
    - Octopus.Action[$($stepName)].Output.Trigger - Set to '$trigger'

Deployment Mode Run Conditions Output Variables:
   	- Octopus.Action[$($stepName)].Output.RunOnRollback
    - Octopus.Action[$($stepName)].Output.RunOnDeploy
    - Octopus.Action[$($stepName)].Output.RunOnRedeploy
    - Octopus.Action[$($stepName)].Output.RunOnDeployOrRollback
    - Octopus.Action[$($stepName)].Output.RunOnDeployOrRedeploy
    - Octopus.Action[$($stepName)].Output.RunOnRollbackOrRedeploy

Version Change Run Conditions Output Variables:
   	- Octopus.Action[$($stepName)].Output.RunOnMajorVersionChange
    - Octopus.Action[$($stepName)].Output.RunOnMinorVersionChange
    - Octopus.Action[$($stepName)].Output.RunOnMajorOrMinorVersionChange
    - Octopus.Action[$($stepName)].Output.RunOnBuildVersionChange
    - Octopus.Action[$($stepName)].Output.RunOnRevisionVersionChange
  
Variable run conditions are always evaluated, even if there is an error.  Use the following examples to control when your step runs.  Replace RunOnDeploy from below examples with one of the variables from above.  
- Always Run: `#{Octopus.Action[$stepName].Output.RunOnDeploy}`  
- Success: Only run when previous steps succeeds `##{unless Octopus.Deployment.Error}#{Octopus.Action[$stepName].Output.RunOnDeploy}##{/unless}`
- Failure: Only run when previous steps fail `##{if Octopus.Deployment.Error}#{Octopus.Action[$stepName].Output.RunOnDeploy}##{/if}`

"@

$runOnRollback = "#{if Octopus.Action[$($stepName)].Output.DeploymentMode == ""Rollback""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRollback' so you can use it as a run condition"
Write-Verbose $runOnRollback
Set-OctopusVariable -Name "RunOnRollback" -Value $runOnRollback

$runOnDeploy = "#{if Octopus.Action[$($stepName)].Output.DeploymentMode == ""Deploy""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnDeploy' so you can use it as a run condition"
Write-Verbose $runOnDeploy
Set-OctopusVariable -Name "RunOnDeploy" -Value $runOnDeploy

$runOnRedeploy = "#{if Octopus.Action[$($stepName)].Output.DeploymentMode == ""Redeploy""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRedeploy' so you can use it as a run condition"
Write-Verbose $runOnRedeploy
Set-OctopusVariable -Name "RunOnRedeploy" -Value $runOnRedeploy

$runOnDeployOrRollback = "#{if Octopus.Action[$($stepName)].Output.DeploymentMode != ""Redeploy""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnDeployOrRollback' so you can use it as a run condition"
Write-Verbose $runOnDeployOrRollback
Set-OctopusVariable -Name "RunOnDeployOrRollback" -Value $runOnDeployOrRollback

$runOnDeployOrRedeploy = "#{if Octopus.Action[$($stepName)].Output.DeploymentMode != ""Rollback""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnDeployOrRedeploy' so you can use it as a run condition"
Write-Verbose $runOnDeployOrRedeploy
Set-OctopusVariable -Name "RunOnDeployOrRedeploy" -Value $runOnDeployOrRedeploy

$runOnRedeployOrRollback = "#{if Octopus.Action[$($stepName)].Output.DeploymentMode != ""Deploy""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRedeployOrRollback' so you can use it as a run condition"
Write-Verbose $runOnRedeployOrRollback
Set-OctopusVariable -Name "RunOnRedeployOrRollback" -Value $runOnRedeployOrRollback

$runOnMajorVersionChange = "#{if Octopus.Action[$($stepName)].Output.VersionChange == ""Major""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnMajorVersionChange' so you can use it as a run condition"
Write-Verbose $runOnMajorVersionChange
Set-OctopusVariable -Name "RunOnMajorVersionChange" -Value $runOnMajorVersionChange

$runOnMinorVersionChange = "#{if Octopus.Action[$($stepName)].Output.VersionChange == ""Minor""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnMinorVersionChange' so you can use it as a run condition"
Write-Verbose $runOnMinorVersionChange
Set-OctopusVariable -Name "RunOnMinorVersionChange" -Value $runOnMinorVersionChange

$runOnMajorOrMinorVersionChange = "#{if Octopus.Action[$stepName].Output.VersionChange == ""Major""}True#{else}#{if Octopus.Action[$stepName].Output.VersionChange == ""Minor""}True#{else}False#{/if}#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnMajorOrMinorVersionChange' so you can use it as a run condition"
Write-Verbose $runOnMajorOrMinorVersionChange
Set-OctopusVariable -Name "RunOnMajorOrMinorVersionChange" -Value $runOnMajorOrMinorVersionChange

$runOnBuildVersionChange = "#{if Octopus.Action[$($stepName)].Output.VersionChange == ""Build""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnBuildVersionChange' so you can use it as a run condition"
Write-Verbose $runOnBuildVersionChange
Set-OctopusVariable -Name "RunOnBuildVersionChange" -Value $runOnBuildVersionChange

$runOnRevisionVersionChange = "#{if Octopus.Action[$($stepName)].Output.VersionChange == ""Revision""}True#{else}False#{/if}"
Write-Host "Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRevisionVersionChange' so you can use it as a run condition"
Write-Verbose $runOnRevisionVersionChange
Set-OctopusVariable -Name "RunOnRevisionVersionChange" -Value $runOnRevisionVersionChange

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "d166457a-1421-4731-b143-dd6766fb95d5",
  "Name": "Calculate Deployment Mode",
  "Description": "This step uses Octopus [System Variables](https://octopus.com/docs/projects/variables/system-variables) to calculate the deployment mode.  \n\n# Deployment Mode\nThe potential modes are:\n- **Deploy**: A newer version is being deployed to the target environment.  For example, `2021.1.4` is being deployed to **Production** to replace `2021.0.5`.\n- **Rollback**: An older version is being deployed to the target environment. For example, `2021.0.5` is being deployed to **Production** to replace `2021.1.4`.\n- **Redeploy**: The same version is being deployed to the target environment.  For example, `2021.1.4` is being deployed to **Production** which already has `2021.1.4`.\n\n**Please note**: This step template uses the release numbers to calculate the deployment mode.  It doesn't look at any packages.\n\n# Version Difference\nAfter calculating the deployment mode, the step template will calculate the version difference.  The potential options are:\n- **Identical**: No differences between the previous release and the current release were found.\n- **Major**: The first number (2021 in 2021.1.2.10) is different between the previous release and the current release.\n- **Minor**: The second number (1 in 2021.1.2.10) is different between the previous release and the current release.\n- **Build**: The third number (2 in 2021.1.2.10) is different between the previous release and the current release.\n- **Revision**: The fourth number (10 in 2021.1.2.10) is different between the previous release and the current release.\n\n# Manual or Automatic Trigger\nThe step template will also determine if the deployment was caused by a trigger or is a manual deployment.  Potential values are `True` (caused by a trigger) or `False` (manual deployment).\n\n# Output Variables\n\nThe following output variables will be set:\n- **DeploymentMode**: Will either be `Deploy`, `Rollback` or `Redeploy`.\n- **Trigger**: Will either be `True` or `False`.  Indicates if this deployment was caused by a trigger (scheduled or deployment target).\n- **VersionChange**: Will either be `Identical`, `Major`, `Minor`, `Build`, or `Revision`.\n\n## Variable Run Condition Output Variables\nTo make it easier to use, the step template will set a number of run condition output variables.  \n\n### Variable Run Condition Usage\nVariable Run Conditions will _always_ be evaluated.  Even if there is an error.  If the run condition comes back as **Truthy** it will run the step.  \n\nTo limit when the step runs, wrap the output variable with an if/then or unless clause:\n- **Always Run**: `#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}`  \n- **Success**: Only run when previous steps succeeds `#{unless Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/unless}`\n- **Failure**: Only run when previous steps fail `#{if Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/if}`\n\n**Hint:** Replace **RunOnDeploy** from the above examples with one of the variables from below.\n\n### Deployment Mode Run Conditions\n- **RunOnDeploy**: Only run the step when the **DeploymentMode** is `Deploy`.\n- **RunOnRollback**: Only run the step when the **DeploymentMode** is `Rollback`.\n- **RunOnRedeploy**: Only run the step when the **DeploymentMode** is `Redeploy`.\n- **RunOnDeployOrRollback**: Only run the step when the **DeploymentMode** is`Deploy` or `Rollback`.\n- **RunOnDeployOrRedeploy**: Only run the step when the **DeploymentMode** is`Deploy` or `Redeploy`.\n- **RunOnRedeployOrRollback**: Only run the step when the **DeploymentMode** is `Redeploy` or `Rollback`.\n\n### Version Change Run Conditions\n- **RunOnMajorVersionChange**: Only run the step when the **VersionChange** is `Major`.\n- **RunOnMinorVersionChange**: Only run the step when the **VersionChange** is `Minor`.\n- **RunOnMajorOrMinorVersionChange**: Only run the step when the **VersionChange** is `Major` or `Minor`.\n- **RunOnBuildVersionChange**: Only run the step when the **VersionChange** is `Build`.\n- **RunOnRevisionVersionChange**: Only run the step when the **VersionChange** is `Revision`.\n\n# Usage \n\n**Important:** This step template is designed for deployment processes only.  Runbooks have no concept of deployments, redeployments, or rollbacks.\n\nThis step was designed to run on a worker (or the Octopus Server).  It can run on targets, but the output variables will all be the same; running on targets will do nothing but waste compute cycles.",
  "Version": 5,
  "ExportedAt": "2021-11-02T13:48:09.120Z",
  "ActionType": "Octopus.Script",
  "Author": "BobJWalker",
  "Packages": [],
  "Parameters": [],
  "Properties": {
    "Octopus.Action.RunOnServer": "true",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$currentReleaseNumber = $OctopusParameters[\"Octopus.Release.Number\"]\n$previousReleaseNumber = $OctopusParameters[\"Octopus.Release.CurrentForEnvironment.Number\"]\n$lastAttemptedReleaseNumber = $OctopusParameters[\"Octopus.Release.PreviousForEnvironment.Number\"]\n$stepName = $OctopusParameters[\"Octopus.Action.StepName\"]\n$triggerName = $OctopusParameters[\"Octopus.Deployment.Trigger.Name\"]\n\nWrite-Host \"The current release number is $currentReleaseNumber\"\nWrite-Host \"The last succesful release to this environment was $previousReleaseNumber\"\nWrite-Host \"The last release that was attempted on this environment was $lastAttemptedReleaseNumber\"\nWrite-Host \"The deployment name is $deploymentName\"\n\nif ($previousReleaseNumber -like \"*-*\")\n{\n\t$previousReleaseNumber = $previousReleaseNumber.SubString(0, $previousReleaseNumber.IndexOf(\"-\"))\n}\n\nif ($currentReleaseNumber -like \"*-*\")\n{\n\t$currentReleaseNumber = $currentReleaseNumber.SubString(0, $currentReleaseNumber.IndexOf(\"-\"))\n}\n\nif ($lastAttemptedReleaseNumber -like \"*-*\")\n{\n\t$lastAttemptedReleaseNumber = $lastAttemptedReleaseNumber.SubString(0, $lastAttemptedReleaseNumber.IndexOf(\"-\"))\n}\n\nWrite-Host \"The non-pre release tag previous version for the environment was $previousReleaseNumber\"\nWrite-Host \"The non-pre release tag current release number is $currentReleaseNumber\"\nWrite-Host \"The non-pre release tag of the last attempted version for the environment was $lastAttemptedReleaseNumber\"\n\n$currentVersion = [System.Version]$currentReleaseNumber\n$previousVersion = [System.Version]$previousReleaseNumber\n$lastAttemptedVersion = [System.Version]$lastAttemptedReleaseNumber\n\n$differentVersions = $false\n$versionToCompare = $previousVersion\nif ($currentVersion -gt $previousVersion)\n{\n\tWrite-Host \"The current release number $currentReleaseNumber is greater than the previous successful release number $previousReleaseNumber.\"\n\tif ($currentVersion -lt $lastAttemptedVersion)\n    {\n    \tWrite-Host \"The current release number $currentReleaseNumber is less than the last attempted release number $lastAttemptedReleaseNumber.  Setting deployment mode to rollback.\"\n\t    $deploymentMode = \"Rollback\"\n        $versionToCompare = $lastAttemptedVersion\n    }\n    else\n    {\n    \tWrite-Host \"The current release number $curentReleaseNumber is greater than the last attempted release number $lastAttemptedReleaseNumber.  Setting deployment mode to deploy.\"\n        $deploymentMode = \"Deploy\"\n    }\n}\nelseif ($currentVersion -lt $previousVersion)\n{\n\tWrite-Host \"The current release number $currentReleaseNumber is less than the previous successful release number $previousReleaseNumber.  Setting deployment mode to rollback.\"\n    $deploymentMode = \"Rollback\"\n    $differentVersions = $true\n}\nelseif ($currentVersion -lt $lastAttemptedVersion)\n{\n\tWrite-Host \"The current release number $currentReleaseNumber is less than the last attempted release number $lastAttemptedReleaseNumber.  Setting the deployment mode to rollback.\"\n    $deploymentMode = \"Rollback\"\n    $differentVersions = $true\n    $versionToCompare = $lastAttemptedVersion\n}\nelse\n{\n\tWrite-Host \"The current release number $currentReleaseNumber matches the previous release number $previousReleaseNumber.  Setting deployment mode to redeployment.\"\n    $deploymentMode = \"Redeploy\"\n}\n\n$differenceKind = \"Identical\"\nif ($differentVersions)\n{\n\tif ($currentVersion.Major -ne $versionToCompare.Major)\n    {\n    \tWrite-Host \"$currentReleaseNumber is a major version change from $versionToCompare\"\n    \t$differenceKind = \"Major\"\n    }\n    elseif ($currentVersion.Minor -ne $versionToCompare.Minor)\n    {\n    \tWrite-Host \"$currentReleaseNumber is a minor version change from $versionToCompare\"\n    \t$differenceKind = \"Minor\"\n    }\n    elseif ($currentVersion.Build -ne $versionToCompare.Build)\n    {\n    \tWrite-Host \"$currentReleaseNumber is a build version change from $versionToCompare\"\n    \t$differenceKind = \"Build\"\n    }\n    elseif ($currentVersion.Revision -ne $versionToCompare.Revision)\n    {\n    \tWrite-Host \"$currentReleaseNumber is a revision version change from $versionToCompare\"\n    \t$differenceKind = \"Revision\"\n    }\n}\n\n$trigger = $false\nif ([string]::IsNullOrWhiteSpace($triggerName) -eq $false)\n{\n\tWrite-Host \"This task was created by trigger $triggerName.\"\n    $trigger = $true\n}\n\nSet-OctopusVariable -Name \"DeploymentMode\" -Value $deploymentMode\nSet-OctopusVariable -Name \"VersionChange\" -Value $differenceKind\nSet-OctopusVariable -Name \"Trigger\" -Value $trigger\n\nWrite-Highlight @\"\nOutput Variables Created:\n   \t- Octopus.Action[$($stepName)].Output.DeploymentMode - Set to '$deploymentMode'\n    - Octopus.Action[$($stepName)].Output.VersionChange - Set to '$differenceKind'\n    - Octopus.Action[$($stepName)].Output.Trigger - Set to '$trigger'\n\nDeployment Mode Run Conditions Output Variables:\n   \t- Octopus.Action[$($stepName)].Output.RunOnRollback\n    - Octopus.Action[$($stepName)].Output.RunOnDeploy\n    - Octopus.Action[$($stepName)].Output.RunOnRedeploy\n    - Octopus.Action[$($stepName)].Output.RunOnDeployOrRollback\n    - Octopus.Action[$($stepName)].Output.RunOnDeployOrRedeploy\n    - Octopus.Action[$($stepName)].Output.RunOnRollbackOrRedeploy\n\nVersion Change Run Conditions Output Variables:\n   \t- Octopus.Action[$($stepName)].Output.RunOnMajorVersionChange\n    - Octopus.Action[$($stepName)].Output.RunOnMinorVersionChange\n    - Octopus.Action[$($stepName)].Output.RunOnMajorOrMinorVersionChange\n    - Octopus.Action[$($stepName)].Output.RunOnBuildVersionChange\n    - Octopus.Action[$($stepName)].Output.RunOnRevisionVersionChange\n  \nVariable run conditions are always evaluated, even if there is an error.  Use the following examples to control when your step runs.  Replace RunOnDeploy from below examples with one of the variables from above.  \n- Always Run: `#{Octopus.Action[$stepName].Output.RunOnDeploy}`  \n- Success: Only run when previous steps succeeds `##{unless Octopus.Deployment.Error}#{Octopus.Action[$stepName].Output.RunOnDeploy}##{/unless}`\n- Failure: Only run when previous steps fail `##{if Octopus.Deployment.Error}#{Octopus.Action[$stepName].Output.RunOnDeploy}##{/if}`\n\n\"@\n\n$runOnRollback = \"#{if Octopus.Action[$($stepName)].Output.DeploymentMode == \"\"Rollback\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRollback' so you can use it as a run condition\"\nWrite-Verbose $runOnRollback\nSet-OctopusVariable -Name \"RunOnRollback\" -Value $runOnRollback\n\n$runOnDeploy = \"#{if Octopus.Action[$($stepName)].Output.DeploymentMode == \"\"Deploy\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnDeploy' so you can use it as a run condition\"\nWrite-Verbose $runOnDeploy\nSet-OctopusVariable -Name \"RunOnDeploy\" -Value $runOnDeploy\n\n$runOnRedeploy = \"#{if Octopus.Action[$($stepName)].Output.DeploymentMode == \"\"Redeploy\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRedeploy' so you can use it as a run condition\"\nWrite-Verbose $runOnRedeploy\nSet-OctopusVariable -Name \"RunOnRedeploy\" -Value $runOnRedeploy\n\n$runOnDeployOrRollback = \"#{if Octopus.Action[$($stepName)].Output.DeploymentMode != \"\"Redeploy\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnDeployOrRollback' so you can use it as a run condition\"\nWrite-Verbose $runOnDeployOrRollback\nSet-OctopusVariable -Name \"RunOnDeployOrRollback\" -Value $runOnDeployOrRollback\n\n$runOnDeployOrRedeploy = \"#{if Octopus.Action[$($stepName)].Output.DeploymentMode != \"\"Rollback\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnDeployOrRedeploy' so you can use it as a run condition\"\nWrite-Verbose $runOnDeployOrRedeploy\nSet-OctopusVariable -Name \"RunOnDeployOrRedeploy\" -Value $runOnDeployOrRedeploy\n\n$runOnRedeployOrRollback = \"#{if Octopus.Action[$($stepName)].Output.DeploymentMode != \"\"Deploy\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRedeployOrRollback' so you can use it as a run condition\"\nWrite-Verbose $runOnRedeployOrRollback\nSet-OctopusVariable -Name \"RunOnRedeployOrRollback\" -Value $runOnRedeployOrRollback\n\n$runOnMajorVersionChange = \"#{if Octopus.Action[$($stepName)].Output.VersionChange == \"\"Major\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnMajorVersionChange' so you can use it as a run condition\"\nWrite-Verbose $runOnMajorVersionChange\nSet-OctopusVariable -Name \"RunOnMajorVersionChange\" -Value $runOnMajorVersionChange\n\n$runOnMinorVersionChange = \"#{if Octopus.Action[$($stepName)].Output.VersionChange == \"\"Minor\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnMinorVersionChange' so you can use it as a run condition\"\nWrite-Verbose $runOnMinorVersionChange\nSet-OctopusVariable -Name \"RunOnMinorVersionChange\" -Value $runOnMinorVersionChange\n\n$runOnMajorOrMinorVersionChange = \"#{if Octopus.Action[$stepName].Output.VersionChange == \"\"Major\"\"}True#{else}#{if Octopus.Action[$stepName].Output.VersionChange == \"\"Minor\"\"}True#{else}False#{/if}#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnMajorOrMinorVersionChange' so you can use it as a run condition\"\nWrite-Verbose $runOnMajorOrMinorVersionChange\nSet-OctopusVariable -Name \"RunOnMajorOrMinorVersionChange\" -Value $runOnMajorOrMinorVersionChange\n\n$runOnBuildVersionChange = \"#{if Octopus.Action[$($stepName)].Output.VersionChange == \"\"Build\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnBuildVersionChange' so you can use it as a run condition\"\nWrite-Verbose $runOnBuildVersionChange\nSet-OctopusVariable -Name \"RunOnBuildVersionChange\" -Value $runOnBuildVersionChange\n\n$runOnRevisionVersionChange = \"#{if Octopus.Action[$($stepName)].Output.VersionChange == \"\"Revision\"\"}True#{else}False#{/if}\"\nWrite-Host \"Setting the output variable 'Octopus.Action[$($stepName)].Output.RunOnRevisionVersionChange' so you can use it as a run condition\"\nWrite-Verbose $runOnRevisionVersionChange\nSet-OctopusVariable -Name \"RunOnRevisionVersionChange\" -Value $runOnRevisionVersionChange"
  },
  "Category": "Octopus",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/calculate-deployment-mode.json",
  "Website": "/step-templates/d166457a-1421-4731-b143-dd6766fb95d5",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAC1QTFRFT6Tl////L5Pg8vj9Y67omsvwPJrisdfzfbzs5fL7y+T32Ov5isLucLXqvt31CJPHWwAABMJJREFUeNrs3deW4jAMAFDF3U75/89dlp0ZhiU4blJEjvQ8hYubLJsA00UCBCIQgQhEIAIRiEAEIhCBCEQgAhGIQAQiEIEIhD8kJm+t+QprfdKfB9HbYpx6CWfspj8HMi+gMgHL/AmQA8W3JTKH+ALFvzCeL0RbpyoCPE9IJeNOSQwh5Z3qd6yRGWQ2qi2cZQWxqj1WzQYSjeoJmJlAklOd4VlArOqPhQEkqBERToeMcfRJBkC0Uep8CfBpjz4JsHJ0zF3dkEWNje0kiB/sUC6eApndaIiCMyAa1PiwJ0AWhRGJHJJQHG2dC7h1rNbO1QOxSA7lNCkkKrQIpJCAB1GREILYIC1NAiwbpKFJgGWDNExcwGstfExcZBCHC6nOglshHtmhViLIig1RNBCN7qjtW8C0Z1UvJcC1Z9XmwMBzzvobmgAyEzgq91dtEEsBsQSQQAFZCSBAATEEEApHZbrVBIkkEIUPSVeB+KtALA0kXQUSrwKZBCIQBnk8Y4i5CsReBeKvkqLM+BCSDWJlrZFvGk9SRTHshkgjZCGAaArIxm3H3grhVzFlW2msfl1ca79UJ1bofYvsDHHlNdTZnlh5MghuPd5NdBDUNZHyCkfktIh03XzALGRPlBDPac7qgWjHZzWcmF5zmmkhidMQ6boKiDXcDTUEaylZqCGJ0Vjvu/fLJtHqhSANEvqb2OYqkOUqEHuVMbJcZdZCGiPhKhC4yjqiIjEE7XThMp8fAWII3mY3kUIQD+AMKQTzPiBhgQ63HlT/KSvgtoi0dq5mCPah1UIE0eh3sT0NhOByvKeAkFzi8PgQomumFhsyOxpIzZN4gLOj5plVwNpR0b2AuePWKBEHQu24pSsJA+LVCeHHQxZ1SiyDIdqok8IOhSSnTottHEQTdyt4ettAj4KkzA4dMikk2Dht2S5ptm1vswnPDxn0YyDZ5oDM3iToo2T5voWaYe+Q+vdjH80QyAzZhCgcDtLMI1Tmtz9w++XHgziHQHJJu/OZ3bs9Xn8gQ72NcP3dKqEfkp10F51xhoIi2I91R+LurXV/5q7pH+wx061CzO16oSQleMyr8fXvwMA0Pro8432DPD/ySx8XrHfSuDAM8n6UhnjQabaiXf5Bq/lREHvEeNtn1rJ08+C/uXkQZHeguxAPC3UvtcJYUogLzZX5hhZZvS6onG5lxXtzWGaygwb79vT/IXhdlNibwlKYOR6T8xjI7W8n+xV7T+GH4tMzWwR+lZhRkJYSsC0thpmCYqyngOz3rN2FLBZ2wZflBCggUHF0Vnp88JKienzIXLSEZCZqU7IKr/gQW9yx3pzV7Y9kvWZWTRRIqDmTtRUnU7b2lLcTYmoqHqnmiO1poER0SPkAeZMAZxaJx0Y3TCdAclsIqDz03ALcyxfTCZBsthoGXWmigGyVhWPLFJJfuuKQWycoEFdXbH4dJJoJxNR1eD/kshz6yn48cF8yW8sFoitflB1w6Q8n+/15Za7oA17/pYNmYgP5fmWm8L1NOHPWgK8kuFew1/JXtOA0yJCv7ah7X8ObUuT5kObU30+fDZm8+zqP+HTIpK0xQ796b5Kv2hSIQAQiEIEIRCACEYhABCIQgQhEIAIRiEAEIpBf8UeAAQAEjtYmlDTcCgAAAABJRU5ErkJggg==",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Tuesday, November 2, 2021