Octopus Deploy Documentation

New Octopus Target Command

Last updated

Targets defined by step packages can be created either by PowerShell or bash functions available in any Octopus script-running context. Not all targets are defined by step packages. The complete list of targets defined by step packages is available below.

Targets from Step Packages
Octopus Deploy has recently developed a new architecture for deployment steps and targets, known as step packages. Step packages are available in Octopus Deploy version 2021.3 and later. To learn more about step packages, read the step package documentation.

Targets defined by step packages use the new generic New-OctopusTarget function to create targets.

To create a target defined by a step package, you will need to know the target identifier, and the inputs required by the target. These can currently be found in the following locations:

Target Identifier Required Inputs
AWS ECS Cluster Identifier Inputs

New octopus target

Command (pwsh): New-OctopusTarget

Parameter Value
-name The Name of the target to create
-targetId The target identifier of target to create
-inputs The inputs required to define the target being created
-roles Comma separated list of Roles to assign
-updateIfExisting Will update an existing target with the same name, create if it doesn't exist
-workerPoolIdOrName Name or Id of the Worker Pool for the deployment target to use. (Optional)

Command (bash) new_octopustarget

Parameter Value
-n | --name The Name of the target to create
-t | --targetId The target identifier of target to create
--inputs The inputs required to define the target being created
--roles Comma separated list of Roles to assign
--update-if-existing Will update an existing target with the same name, create if it doesn't exist
--worker-pool Name or Id of the Worker Pool for the deployment target to use. (Optional)

Examples

The below examples demonstrate creating a new AWS ECS Cluster target, evidenced by the aws-ecs-target target identifier. These scripts would typically be invoked after creating the cluster in a preceeding step. The required information can be passed to these scripts via passing parameters, or via output variables published in preceeding steps, or can simply be hard-coded.

$inputs = @"
{
    "clusterName": "$($OctopusParameters["clusterName"])",
    "region": "$($OctopusParameters["region"])",
    "awsAccount": "$($OctopusParameters["awsAccount"])",
}
"@

New-OctopusTarget -Name "$($OctopusParameters["target_name"])" -TargetId "aws-ecs-target" -Inputs $inputs -Roles "$($OctopusParameters["role"])"
read -r -d '' INPUTS <<EOT
{
    "clusterName": "$(get_octopusvariable "clusterName")",
    "name": "$(get_octopusvariable "target_name")",
    "awsAccount": "$(get_octopusvariable "awsAccount")",
}
EOT

new_octopustarget -n "$(get_octopusvariable "target_name")" -t "aws-ecs-target" --inputs "$INPUTS" --roles "$(get_octopusvariable "role")"

Need support? We're here to help.