Trigger a deployment

Use the Continuous Delivery API to trigger a deployment from one of your branches to a Puppet Enterprise environment.

Before you begin:
In order to trigger a deployment, you need to collect the following:
If the deployment targets a protected environment, it does not run without approval. An approval request is created in the Continuous Delivery console that must be approved to trigger the code to be deployed to the environment.
  1. Get the deployment policy details. A deployment policy describes how you want the code from your source branch to be deployed to your Puppet Enterprise instance. You can list all the policies available in your workspace using:
    auth_header="Authorization: <API token>"
    uri="https://<CD4PE host>/cd4pe/api/v1/deployments/policies?workspaceId=<workspace ID>&projectName=my_control_repo&projectType=CONTROL_REPO"
    curl --insecure --header "$type_header" --header "$auth_header" --request GET "$uri"

    This returns information about the policies in your workspace. For example, it might look similar to the following:

    {  
      "deploymentPolicies" : [  
        {  
          "custom" : false,  
          "displayName" : "Direct deployment policy",  
          "name" : "cd4pe_deployments::direct",  
          "parameters" : [  
            {  
              "name" : "max_node_failure",  
              "type" : "Optional[Integer]",  
              "value" : null  
            },  
            {  
              "name" : "noop",  
              "type" : "Boolean",  
              "value" : false  
            },  
            {  
              "name" : "fail_if_no_nodes",  
              "type" : "Boolean",  
              "value" : true  
            }  
          ]  
        }, 
        ....  
      ]  
    }   

    From this you can choose which policy you want to use for this deployment and supply it to the deployment request, customizing the values of any parameters that you want to change.

  2. Trigger the deployment. Once you have collected all the information you need, you can trigger the deployment.
    data="$(cat <<EOF
    {
      "workspaceId": "<workspace ID>",
      "projectName": "<name of control repo or module to deploy from>",
      "projectType": "CONTROL_REPO",
      "displayName": "Deployment to production on example-pe",
      "description": "Run Production Deployment from main",
      "maxRuntime": 3600000,
      "deploymentPolicy": {
        "custom": false,
        "displayName": "Direct deployment policy",
        "name": "cd4pe_deployments::direct",
        "parameters": [
          {
            "name" : "max_node_failure",
            "type" : "Optional[Integer]",
            "value" : 1
          },
          {
            "name" : "noop",
            "type" : "Boolean",
            "value" : false
          },
          {
            "name" : "fail_if_no_nodes",
            "type" : "Boolean",
            "value" : true
          }
        ],
        "controlRepoId": {
          "domain": "<workspace ID>",
          "name": "<project name>"
          }
        },
        "deploymentTarget": {
          "type": "NODE_GROUP",
          "nodeGroupId": "<ID of the enviornment node group to deploy to>",
          "environmentPrefix": ""
        },
        "puppetEnterpriseServer": "example-pe",
        "repoTargetBranch": "<branch to deploy to>",
        "repoSourceBranch": "<branch to deploy from>",
        "repoSourceSha": "<SHA of HEAD of branch>"
    }
    EOF
    )"
    type_header='Content-Type: application/json'
    auth_header="Authorization: <API token>"
    uri="https://<CD4PE host>/cd4pe/api/v1/deployments/trigger"
    curl --insecure --header "$type_header" --header "$auth_header" --request POST "$uri" --data "$data"