Remove a feature from a process step via api

Hi,

I am learning my way round the API but would like some direction on how to remove a feature { “IIS web site and application pool”} from a process step via the API …

I’m using powershell to call the api and can dig down to find the properties of where it is stored but not sure if I should be changing it there and posting back?

here’s how i’m getting to the field… should it be done this way ?

$headers = @{“X-Octopus-ApiKey”=“API-XXX”;}
$t = Invoke-restmethod (“http://octo/api/deploymentprocesses/deploymentprocess-projects-644”) -Headers $Headers -Method Get
$a = $t.Steps | Where-Object {$.id -eq “baf95ccb-2172-465f-bd89-c78b93c1875e”}
$a = $a.actions | ?{$
.id -eq “e400040d-03e7-44a4-bc25-1dcd622b0aec”}
$a.properties | Select-Object “Octopus.Action.EnabledFeatures”

and the output is

Octopus.Action.EnabledFeatures

Octopus.Features.CustomDirectory,Octopus.Features.ConfigurationVariables,Octopus.Features.IISWebSite

Thanks

Kris

Hi Kris,

Thanks for getting in touch!

First of all let me mention that this may cause lots of issues, and not really something we encourage our users to do. So please take due care when modifying deployment processes by editing strings within it.

I would definitely test this on a non-production project first to make sure that the modifications won’t break your project.

The script below is an extension of your script to modify the enabled features to remove the IIS web site and application pool feature and then posting the modified deployment process to the server, I can’t stress enough that you should be very careful running this on a production project as you may break it, use it at your own risk.

$features = $a.properties | Select-Object "Octopus.Action.EnabledFeatures"
$x = [System.Collections.ArrayList]$features.'Octopus.Action.EnabledFeatures'.Split(",", [StringSplitOptions]::RemoveEmptyEntries)
$x.Remove("Octopus.Features.IISWebSite")
$a.Properties.'Octopus.Action.EnabledFeatures' = $x -join ","

Invoke-RestMethod ("http://octo/api/deploymentprocesses/deploymentprocess-projects-644") -Headers $Headers -Method Put -Body ($t | ConvertTo-Json -Depth 10)

Thank you and kind regards,
Henrik

Hi Henrik :slight_smile:

That’s brilliant ! this is being used in conjunction with cloning a project so we can test config changes before going live so no adjustments to a live project will be made :slight_smile:

Will test and feedback the results ! :slight_smile:

again many thanks

Kris

So i did find a very unusual way of getting where i needed to be using powershell…

I very much doubt anyone would want to go down this route but I simply

$t = Invoke-restmethod (“http://octo/api/deploymentprocesses/$name”) -Headers $Headers -Method Get
$t | Export-Clixml c:\project.txt
(Get-Content c:\project.txt) -replace “Octopus.Features.CustomDirectory,Octopus.Features.ConfigurationVariables,Octopus.Features.IISWebSite”,“Octopus.Features.CustomDirectory,Octopus.Features.ConfigurationVariables” | Set-Content C:\project.txt
$t = Import-Clixml C:\project.txt
$t = $t | convertto-json -Depth 10
Invoke-RestMethod (“http://octo/api/deploymentprocesses/$name”) -Headers $Headers -Method Put -Body $t

all i can say it works brilliantly and is a very easy way to change variables etc :slight_smile:

Kris