Trigger a pipeline

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

Before you begin:
In order to trigger a pipeline, you need to collect the following:
  • The ID of the workspace containing the pipeline you want to trigger
  • The name of the control repo or module whose pipeline you want to trigger
  • The ID of the pipeline belonging to that code project
  • The SHA with which you want to trigger the pipeline
  1. Get the pipeline ID, which are returned in the details for control repos and modules. You can find this using:
    auth_header="Authorization: <API token>"
    uri="https://<CD4PE host>/cd4pe/api/v1/<control-repos OR modules>/<repo name>?workspaceId=d5"
    curl --insecure --header "$type_header" --header "$auth_header" --request GET "$uri"

    This returns information about the control repo. For example, it might look similar to the following:

    {  
      "name": "my_control_repo",  
      "srcRepoProvider": "BITBUCKET",  
      "srcRepoOwner": "{a8b34a31-8814-4c5d-aca1-580ee518c290}",  
      "srcRepoName": "my_control_repo",  
      "srcRepoId": "{a8b34a31-8814-4c5d-aca1-580ee518c290}",  
      "srcRepoDisplayName": "my_control_repo",  
      "pipelines": [  
        {  
          "name": "regex",  
          "pipelineId": "e64kq33s04kh05pbxfr6w8e9y"  
        },  
        {  
          "name": "main",  
          "pipelineId": "1jqloxhyphh0w03r8h82i996tr"  
        }  
      ], 
      ... 
    }   

    From this you can choose which pipeline you want to trigger.

  2. Trigger the pipeline. Once you have collected all the information you need, you can trigger the pipeline.
    data="$(cat <<EOF
    {
      "workspaceId": "<workspace ID>",
      "projectName": "<name of control repo or module>",
      "sha": "<SHA to run against>"
    }
    EOF
    )"
    type_header='Content-Type: application/json'
    auth_header="Authorization: <API token>"
    uri="https://<CD4PE host>/cd4pe/api/v1/pipelines/<pipeline ID>/trigger"
    curl --insecure --header "$type_header" --header "$auth_header" --request POST "$uri" --data "$data"