Search code examples
pythonkuberneteskubeflowkubeflow-pipelines

How to obtain the Kubeflow pipeline run name from within a component?


I'm working with Kubeflow pipelines. I would like to access the "Run name" from inside the a task component. For example in the below image the run name is "My first XGBoost run" - as seen in the title.

enter image description here

I know for example it's possible to obtain the workflow ID by passing the parameter {{workflow.uid}} as a command line argument. I have also tried the Argo variable {{ workflow.name }} but this doesn't give the correct string.


Solution

  • You can use {{workflow.annotations.pipelines.kubeflow.org/run_name}} argo variable to get the run_name

    For example,

    @func_to_container_op
    def dummy(run_id, run_name) -> str:
        return run_id, run_name
    
    @dsl.pipeline(
        name='test_pipeline',
    )
    def test_pipeline():
      dummy('{{workflow.labels.pipeline/runid}}', '{{workflow.annotations.pipelines.kubeflow.org/run_name}}')
    
    

    You will find that the placeholders will be replaced with the correct run_id and run_name.