Trigger a workflow remotely

1 minute read

Run a CloudBees platform workflow without using the platform UI. You can use an API call to invoke a manual workflow, including one with parameters. In this way, you can use an external tool, such as an IDE, to trigger platform workflows.

A manual workflow must contain on.workflow_dispatch in the YAML file.

Prerequisites

You must first perform the following tasks in order to trigger a workflow remotely:

Integrate the platform API and invoke a workflow

Integrate the CloudBees platform API into your external tool, authenticating with your personal access token. Connecting the platform to your external tool allows you to invoke a manually triggered workflow without using the platform UI.

To integrate the platform API and invoke a workflow:

  1. Select the component containing the workflow (containing a manual trigger) that you want to run remotely.

  2. Locate the component ID in your browser address bar, displayed as <COMPONENT_ID> in the example below:

    https://cloudbees.io/orgs/<YOUR_ORGANIZATION>/components/runs?componentId=<COMPONENT_ID>&organizationId=<ORGANIZATION_ID>
  3. Create an endpoint URL as below, by replacing <COMPONENT_ID> with your component ID.

    https://api.cloudbees.io/v2/components/<COMPONENT_ID>/trigger
  4. Form a curl command as below:

    curl --location '<ENDPOINT_URL>' \ (1) --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <PERSONAL_ACCESS_TOKEN>' \ (2) --data '{ "branch_name":"<REPOSITORY_BRANCH>",(3) "workflow_file_name":"<WORKFLOW_FILENAME>"(4) }'
    1 Replace <ENDPOINT_URL> with your endpoint URL.
    2 Replace <PERSONAL_ACCESS_TOKEN> with your personal access token.
    3 Replace <REPOSITORY_BRANCH> with your repository branch name.
    4 Replace <WORKFLOW_FILENAME> with your workflow filename.
  5. Copy the curl command into your CLI of choice and run the command.

The external tool invokes the specified manually triggered platform workflow.