Creating a custom component for use in the pipeline
Last updated: Jun 07, 2024
Creating a custom component for use in the pipeline
A Orchestration Pipelines custom component runs a script that you write. You can use custom components to share reusable scripts between pipelines.
You create custom components as project assets. You can then use the components in pipelines you create in that project. You can create as many custom components for pipelines as needed. Currently, you must create a custom component programmatically,
by using a Python function.
Creating a component as a project asset
Copy link to section
To create a custom component, use the Python client to authenticate with IBM Orchestration Pipelines, code the component, then publish the component to the specified project. After it is available in the project, you can assign the component
to a node in a pipeline and run it as part of a pipeline flow.
This example demonstrates the process of publishing a component that adds two numbers together, then assigns the component to a pipeline node.
Publish a function as a component with the Python client. Run the following code in a Jupyter Notebook in a project of IBM watsonx.
# Install libraries
! pip install ibm-orchestration-pipelines
# Authenticationfrom ibm_orchestration_pipelines import OrchestrationPipelines
apikey = ''
project_id = 'your_project_id'
client = OrchestrationPipelines(apikey, url=service_url)
# Define the function of the component# If you define the input parameters, users are required to # input them in the UIdefadd_two_numbers(a: int, b: int) -> int:
print('Adding numbers: {} + {}.'.format(a, b))
return a + b + 10# Other possible functions might be sending a Slack message,# or listing directories in a storage volume, and so on.# Publish the component
client.publish_component(
name='Add numbers', # Appears in UI as component name
func=add_two_numbers,
description='Custom component adding numbers', # Appears in UI as component description
project_id=project_id,
overwrite=True, # Overwrites an existing component with the same name
)
About cookies on this siteOur websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising.For more information, please review your cookie preferences options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.