chocolatey / chocolatey-licensed-issues

Issues for Licensed Editions of Chocolatey
19 stars 13 forks source link

Central Management API - Allow For Creation of Advanced CCM Deployments Via the API #291

Closed ryanrichter94 closed 2 years ago

ryanrichter94 commented 2 years ago

Request

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.

References

┆Issue is synchronized with this Gitlab issue by Unito

vexx32 commented 2 years ago

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 for a basic step, it can be modified so the step is considered an Advanced step:

$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.

gep13 commented 2 years ago

@vexx32 what are your thoughts on adding this as an example to the examples section that you already linked to? Seems like a sensible addition to me (with the added caveat regarding permissions that you have also stated here).

vexx32 commented 2 years ago

Makes sense to me. Should we transfer this to the docs repo?

gep13 commented 2 years ago

@vexx32 hmm, this is now synced via Unito to another issue, so I don't think moving it is a good idea, no. I would be more inclined to create a new issue, and link to it from here, and then close this one out.

vexx32 commented 2 years ago

Duplicated this issue to https://github.com/chocolatey/docs/issues/352, closing this one for now. 🙂