Search code examples
azureazure-machine-learning-serviceazure-ml-pipelines

Pass AzureML job's name to pipeline


I have a scheduled AzureML pipeline. Every run of the pipeline gets an autogenerated name in the AzureML UI. I'd like to pass this name to the pipeline. How could I do that?

The scheduled pipeline is created as follows:

step = CommandStep(command="myscript.sh --job-name=<AZUREML JOB NAME>")
pipeline = Pipeline(workspace, [step])
published_pipeline = pipeline.publish(name='my pipeline')
schedule = Schedule.create(workspace=workspace, pipeline_id=published_pipeline.id, ...)

I would like to pass the run name create by AzureML e.g. as a command line parameter as in the example above.


Solution

  • From within an AzureML pipeline (SDK v2), you can read the run_id from an environment variable and then get the display name as follows

    client = MLClient( ... )
    job = client.jobs.get(os.environ["AZUREML_RUN_ID"])
    job.display_name