Currently when attempting to add a step to a deployment process I am receiving a 400 error. This is a cloud implementation, as such I cannot see any detailed information regarding this error.
In a previous post on this forum it said that $scriptBody was an issue, so I updated mine to a simplistic script.
$scriptBody = ‘Write-Host “SODTESTING because powershell makes me sad”’
This is the function that is failing…
function Add-Action($stepName, $stepTemplateName, $steps){
$alreadyAdded = Get-AddedAlreadyStatus $actionTemplateId $steps
if ($alreadyAdded -eq $true){
Write-Host “—> Step: $($stepTemplateName) - Already in project, will not add.” -ForegroundColor Yellow
return;
}
#convert the array to a collection
$stepCollection = {$deploymentProcess.Steps}.Invoke()
Add new step to process
$step = @{
Name = “$stepTemplateName”
Properties = @{
‘Octopus.Action.TargetRoles’ = $roles
}
Condition = “Success”
StartTrigger = “StartAfterPrevious”
PackageRequirement = “LetOctopusDecide”
Actions = @(
@{
ActionType = “Octopus.Script”
Name = “Run a script”
Environments = @()
ExcludedEnvironments = @()
Channels = @()
TenantTags = @()
Properties = @{
‘Octopus.Action.RunOnServer’ = “false”
‘Octopus.Action.EnabledFeatures’ = “”
‘Octopus.Action.Script.ScriptSource’ = “Inline”
‘Octopus.Action.Script.Syntax’ = “PowerShell”
‘Octopus.Action.Script.ScriptBody’ = $scriptBody
‘Octopus.Action.Template.Id’ =$actionTemplateID
‘Octopus.Action.Template.Version’ = $actionTemplateVersion
}
Packages = @()
IsDisabled = $false
WorkerPoolId = “”
WorkerPoolVariable = “”
Container = @{
“FeedId” = $null
“Image” = $null
}
CanBeUsedForProjectVersioning = $false
IsRequired = $false
}
)
}
$stepCollection.Insert(0, $step)
#convert it back to an array
$stepCollection | Set-Variable stepArray
$deploymentProcess.Steps = $stepArray
$jsonPayload = $deploymentProcess | ConvertTo-Json -Depth 10
Write-Host “—> JSON Payload”
Write-Host $jsonPayload
if ($previewOnly -eq $false){
Invoke-RestMethod -Method Put -Uri “$octopusURL/api/$($spaceId)/deploymentprocesses/$($project.DeploymentProcessID)” -Headers $header -Body $jsonPayload
Write-Host “Attempted to update Deployment Process”
}
}