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
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 Cloud Pak for Data as a Service.
# Install libraries ! pip install ibm-orchestration-pipelines # Authentication from 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 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 )
To generate a new API key:
- Go to the IBM Cloud home page
- Click Manage > Access (IAM)
- Click API keys
- Click Create
-
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
Use these Python client methods to manage custom pipeline components.
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 |
Parent topic: Creating a pipeline