A custom pipeline component executes a script 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, to create a custom component you must create one programmatically, using a Python function.
Creating a component as a project asset
To create a custom component, use the Python client to authenticate with IBM Watson Pipelines, code the component, then publish the component to the specified project. After it is available in the project, you can assign it 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 assigning the component to a pipeline node.
-
Publish a function as a component with the latest Python client. Run the following code in a Jupyter notebook in a project of IBM watsonx.
# Install libraries ! pip install ibm-watson-pipelines==1.0.0 # Authentication from ibm_watson_pipelines import WatsonPipelines apikey = '' project_id = 'your_project_id' client = WatsonPipelines.from_apikey(apikey) # Define the function of the component # If you define the input parameters, users are required to # input them in the UI def add_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 )
-
Drag the node called Run Pipelines component under Run to the canvas.
-
Choose the name of the component that you want to use.
-
Connect and run the node as part of a pipeline job.
Manage pipeline components
To manage your components, use the Python client to manage them.
Method | Function |
---|---|
client.get_components(project_id=project_id) |
List components from a project |
client.get_component(project_id=project_id, component_id=component_id) |
Get a component by ID |
client.get_component(project_id=project_id, name=component_name) |
Get a component by name |
client.publish_component(component name) |
Publish a new component |
client.delete_component(project_id=project_id, component_id=component_id) |
Delete a component by ID |
Import and export
IBM Watson Pipelines can be imported and exported with pipelines only.
Parent topic: Creating a pipeline