chocolatey / chocolatey/docs

(Central Management) Add API documentation example for advanced deployment steps

Open
#352 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
MDX
Stars
223
Forks
248
Avg merge
1d 26m
Merged PRs (30d)
4

Description

Originally from https://github.com/chocolatey/chocolatey-licensed-issues/issues/291

> Currently using the /api/services/app/DeploymentPlans/CreateOrEdit API call. You are only able to specify a basic deployment step of installing, upgrading, or uninstalling a specific package.
>
> Would like the capability to enter in Powershell to run an advanced deployment instead of just being tied to the options of a basic deployment step. Such as stopping services and other powershell operations.

(...)

> This feature already exists, though we could definitely use better documentation around it. The essence of it is that it's very similar to a basic step, but you need to target a slightly different API endpoint, and the script property is then interpreted as a full PowerShell script.
>
> Taking the example from our [api examples](https://docs.chocolatey.org/en-us/central-management/usage/api/examples#add-a-deployment-step) for a basic step, it can be modified so the step is considered an Advanced step:

```powershell
$params = @{
# Note the `CreateOrEditPrivileged` endpoint is used for advanced steps instead of `CreateOrEdit`
Uri = "https://$CcmServerHostname/api/services/app/DeploymentSteps/CreateOrEditPrivileged"
Method = "POST"
WebSession = $Session
ContentType = 'application/json'
Body = @{
deploymentPlanId = $deployment.Id
name = "Choco Upgrade All"
validExitCodes = "0, 1605, 1614, 1641, 3010"
executionTimeoutInSeconds = 14400
machineContactTimeoutInMinutes = "0"
failOnError = $true
requireSuccessOnAllComputers = $false
deploymentStepGroups = @(
@{ groupId = $Group.Id; groupName = $Group.Name }
)
# For advanced steps, enter a powershell script as a string
script = 'Write-Host "This is treated as a PowerShell script"'
} | ConvertTo-Json
}
$null = Invoke-RestMethod @params
```

> Note that this won't work if the user you're working with the API from doesn't have permissions to use Advanced steps in deployments.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.