0 / 0
Creating a custom component for use in the pipeline
Last updated: Jun 10, 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

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.

  1. 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:

    1. Go to the IBM Cloud home page
    2. Click Manage > Access (IAM)
    3. Click API keys
    4. Click Create
  2. Drag the node called Run Pipelines component under Run to the canvas.
    Retrieving the custom component node

  3. Choose the name of the component that you want to use.
    Choosing the actual component function

  4. Connect and run the node as part of a pipeline job.
    Connecting the component

Manage pipeline components

Use these Python client methods to manage custom pipeline components.

Table 1. Manage 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

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more