Creation of Compute Instance CLI pipeline

Giovana Claro 0 Reputation points
2023-08-03T14:16:00.1666667+00:00

I'm trying to use CLI in Azure DevOps build pipelines to create a compute instance with the following code:

az ml computetarget create computeinstance -g $(azureml.resourceGroup) -w $(azureml.workspaceName) -n $(amlcompute.instanceName) -s $(amlcompute.vmSize)

It works fine the first time, but if it already exists and it try to creates I get an error, that this name is unavailabe. Is there a way I can create if it doesn't exist and ignore if it exists?
I thoght this command would be idempotent.

I'm creating this through a shell inline script in CLI task on azure pipelines, do you think is the best practice I can follow or should I use a yml file?

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,231 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,683 questions
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 53,941 Reputation points
    2023-08-04T02:22:52.9233333+00:00

    Hello @Giovana Claro

    Thanks for reaching out to us, based on the information you provided, yes, the az ml computetarget create command is not idempotent, which means that it will fail if the compute instance already exists.

    To create a compute instance if it doesn't exist and ignore if it exists, you can use the az ml computetarget show command to check if the compute instance already exists before creating it.

    You can refer to this sample - if ! az ml computetarget show --name $(amlcompute.instanceName) --resource-group $(azureml.resourceGroup) --workspace-name $(azureml.workspaceName) &> /dev/null; then az ml computetarget create computeinstance -g $(azureml.resourceGroup) -w $(azureml.workspaceName) -n $(amlcompute.instanceName) -s $(amlcompute.vmSize) fi

    Regarding your second question, using a YAML file is generally considered a best practice for defining Azure resources, including compute instances. You can define your compute instance in a YAML file and use the az deployment group create command to deploy the YAML file. Here is an example:

    az deployment group create --resource-group $(azureml.resourceGroup) --template-file compute-instance.yml --parameters instanceName=$(amlcompute.instanceName) vmSize=$(amlcompute.vmSize) In this example, compute-instance.yml is the YAML file that defines the compute instance, and instanceName and vmSize are the parameters that are passed to the YAML file.

    I hope this helps.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.