Reputation: 369
I have been searching to disable individual process step using Octopus API. I have a project which consist 10 steps and I'm using TeamCity as a CI tool. So I have a condition where 1 step needs to be disabled (whichever I want to) when I run a build. I want to disable/skip a particular step while promoting release as well.
I was able to reach till below step which is not working
Add-Type -Path 'Octopus.Client.dll'
$apikey = 'API-23H4GJ243HG2H3J423433H' # Get this from your profile
$octopusURI = 'http://localhost:9090' # Your server address
$projectName = "Demo" # Name of your project
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$Header = @{ "X-Octopus-ApiKey" = $apikey }
$project = $repository.Projects.FindByName($projectName)
$deploymentProcess = $repository.DeploymentProcesses.Get($project.DeploymentProcessId)
foreach ($step in $deploymentProcess.Steps)
{
if($step.Name = "DemoStep")
{
$step.Actions.IsDisabled = 'True'
break
}
}
$repository.DeploymentProcesses.Modify($deploymentProcess)
Or
$Body = @{
IsDisabled = "True"
} | ConvertTo-Json
Invoke-RestMethod -Uri $OctopusURI/api/deploymentprocesses/deploymentprocess-Projects-21/ -Method PUT`
-Headers $Header -Body $Body
Or Octo.exe --skip=stepname will only work in this case?
Can you please help figure out this?
Thanks, Imran
Upvotes: 1
Views: 1517
Reputation: 369
I got the working script to disable process step from Octopus Support Support Link and I extended that script to get both Disable and Enable functionality.
##SETUP##
$OctopusURL = ""
$APIKey = ""
$ProjectName = ""
$StepName = ""
$DesiredAction = "Enable" #Enable or Disable
##PROCESS#
Add-Type -Path 'Octopus.Client.dll'
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusURL, $apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$Project = $repository.Projects.FindByName($ProjectName)
$deploymentProcess = $repository.DeploymentProcesses.Get($project.DeploymentProcessID)
$WasDeploymentProcessModified = $false
foreach ($step in $deploymentProcess.Steps) {
foreach ($Action in $step.actions) {
if ($Action.name -eq $StepName) {
"Step [$StepName] found"
if ($DesiredAction -eq "Disable") {
if ($Action.IsDisabled -eq $false) {
"Disabling step [$StepName]"
$Action.IsDisabled = $true
$WasDeploymentProcessModified = $true
}
Else {
"Step was already disabled"
}
}
elseif ($DesiredAction -eq "Enable") {
if ($Action.IsDisabled -eq $true) {
"Enabling step [$StepName]"
$Action.IsDisabled = $false
$WasDeploymentProcessModified = $true
}
Else {
"Step was already enabled"
}
}
}
}
}
if ($WasDeploymentProcessModified) {
"Steps in the deployment process of [$ProjectName] were changed. Saving changes to database..."
$repository.DeploymentProcesses.Modify($deploymentProcess)
}
else {
"No step was modified for [$ProjectName]"
}
Upvotes: 2