Use any API client, such as an external IDE, to trigger a CloudBees Unify workflow run using a curl command.
Users with the appropriate permissions can start a workflow without accessing the UI, as long as the workflow contains a workflow_dispatch trigger.
Prerequisites
You must first perform the following tasks to trigger a workflow remotely:
-
Create a workflow with a manual trigger in CloudBees Unify.
-
Generate a personal access token in CloudBees Unify.
Form the curl command
Configure a curl command to invoke the manually-triggered workflow.
To form the curl command:
-
Select an organization, and then select the component with the manually-triggered workflow that you want to run remotely.
-
Locate the component ID and copy it for use in the
curlcommand. -
In your component, select a workflow containing a
workflow_dispatchtrigger from Workflows, and then copy the following for use in thecurlcommand:-
The workflow branch name.
-
The workflow filename, for example,
my-workflow.yaml.To be triggered using an API, a workflow must contain a workflow_dispatchtrigger.
-
-
(Optional) Add input parameters to the trigger as key/value pairs, to customize workflow runtime behavior.
-
Using the copied information, configure the
curlcommand in the format below:curl --location 'https://api.cloudbees.io/v2/components/<COMPONENT_ID>/trigger' \ (1) --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <PERSONAL_ACCESS_TOKEN>' \ (2) --data '{ "branchName": "<REPOSITORY_BRANCH>", (3) "workflowFileName": "<WORKFLOW_FILE.YAML>", (4) "inputs": { (5) "<string_parameter_name>": "<string_value>", "<number_parameter_name>": "<number_value>", "<boolean_parameter_name>": "<boolean_value>", "<choice_parameter_name>": "<choice_option1>,<choice_option2>,<choice_option3>,<default_option>" } }'1 Replace <COMPONENT_ID>with the CloudBees Unify component ID to form the endpoint URL.2 Replace <PERSONAL_ACCESS_TOKEN>with your personal access token.3 Replace <REPOSITORY_BRANCH>with the repository branch name.4 Replace <WORKFLOW_FILENAME.YAML>with the workflow filename. For example,my-filename.yaml.5 Include any applicable parameter names and valid values in the trigger inputs.
The curl command is configured to run your workflow remotely.
Usage example
The following shows an example workflow with manual trigger inputs and the corresponding curl command to invoke it:
apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: Remote workflow on: push: branches: - "test-branch" workflow_dispatch: inputs: my_string: type: string default: my value my_boolean: type: boolean default: true my_choice: type: choice options: - https://example.com - https://example.net - https://example.io default: https://example.com jobs: build: steps: - name: Say hello uses: docker://golang:1.20.3-alpine3.17 shell: sh run: | echo "hello world"
curl --location 'https://api.cloudbees.io/v2/components/abc123-def456-ghi789/trigger' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer your-personal-access-token-here' \ --data '{ "branchName": "test-branch", "workflowFileName": "remote-workflow.yaml", "inputs": { "my_string": "custom value", "my_boolean": "false", "my_choice": "https://example.net" } }'
Trigger the workflow run by executing the curl command in an external tool.