Skip to content

Commit 1ac32b0

Browse files
committed
Reverting exec docs testing change
1 parent 61f5f05 commit 1ac32b0

File tree

1 file changed

+50
-84
lines changed

1 file changed

+50
-84
lines changed

articles/batch/quick-create-cli.md

Lines changed: 50 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: 'Quickstart: Use the Azure CLI to create a Batch account and run a job'
33
description: Follow this quickstart to use the Azure CLI to create a Batch account, a pool of compute nodes, and a job that runs basic tasks on the pool.
44
ms.topic: quickstart
55
ms.date: 04/12/2023
6-
ms.custom: mvc, devx-track-azurecli, mode-api, linux-related-content, innovation-engine
6+
ms.custom: mvc, devx-track-azurecli, mode-api, linux-related-content
77
---
88

99
# Quickstart: Use the Azure CLI to create a Batch account and run a job
@@ -20,91 +20,63 @@ After you complete this quickstart, you understand the [key concepts of the Batc
2020

2121
You can run the Azure CLI commands in this quickstart interactively in Azure Cloud Shell. To run the commands in the Cloud Shell, select **Open Cloudshell** at the upper-right corner of a code block. Select **Copy** to copy the code, and paste it into Cloud Shell to run it. You can also [run Cloud Shell from within the Azure portal](https://shell.azure.com). Cloud Shell always uses the latest version of the Azure CLI.
2222

23-
Alternatively, you can [install Azure CLI locally](/cli/azure/install-azure-cli) to run the commands. The steps in this article require Azure CLI version 2.0.20 or later. Run [az version](/cli/azure/reference-index?#az-version) to see your installed version and dependent libraries, and run [az upgrade](/cli/azure/reference-index?#az-upgrade) to upgrade. If you use a local installation, sign in to Azure by using the appropriate command.
23+
Alternatively, you can [install Azure CLI locally](/cli/azure/install-azure-cli) to run the commands. The steps in this article require Azure CLI version 2.0.20 or later. Run [az version](/cli/azure/reference-index?#az-version) to see your installed version and dependent libraries, and run [az upgrade](/cli/azure/reference-index?#az-upgrade) to upgrade. If you use a local installation, sign in to Azure by using the [az login](/cli/azure/reference-index#az-login) command.
2424

2525
>[!NOTE]
2626
>For some regions and subscription types, quota restrictions might cause Batch account or node creation to fail or not complete. In this situation, you can request a quota increase at no charge. For more information, see [Batch service quotas and limits](batch-quota-limit.md).
2727
2828
## Create a resource group
2929

30-
Run the following [az group create](/cli/azure/group#az-group-create) command to create an Azure resource group. The resource group is a logical container that holds the Azure resources for this quickstart.
30+
Run the following [az group create](/cli/azure/group#az-group-create) command to create an Azure resource group named `qsBatch` in the `eastus2` Azure region. The resource group is a logical container that holds the Azure resources for this quickstart.
3131

3232
```azurecli-interactive
33-
export RANDOM_SUFFIX=$(openssl rand -hex 3)
34-
export REGION="canadacentral"
35-
export RESOURCE_GROUP="qsBatch$RANDOM_SUFFIX"
36-
3733
az group create \
38-
--name $RESOURCE_GROUP \
39-
--location $REGION
40-
```
41-
42-
Results:
43-
44-
<!-- expected_similarity=0.3 -->
45-
46-
```JSON
47-
{
48-
"id": "/subscriptions/xxxxx/resourceGroups/qsBatchxxx",
49-
"location": "eastus2",
50-
"managedBy": null,
51-
"name": "qsBatchxxx",
52-
"properties": {
53-
"provisioningState": "Succeeded"
54-
},
55-
"tags": null,
56-
"type": "Microsoft.Resources/resourceGroups"
57-
}
34+
--name qsBatch \
35+
--location eastus2
5836
```
5937

6038
## Create a storage account
6139

6240
Use the [az storage account create](/cli/azure/storage/account#az-storage-account-create) command to create an Azure Storage account to link to your Batch account. Although this quickstart doesn't use the storage account, most real-world Batch workloads use a linked storage account to deploy applications and store input and output data.
6341

64-
Run the following command to create a Standard_LRS SKU storage account in your resource group:
42+
Run the following command to create a Standard_LRS SKU storage account named `mybatchstorage` in your resource group:
6543

6644
```azurecli-interactive
67-
export STORAGE_ACCOUNT="mybatchstorage$RANDOM_SUFFIX"
68-
6945
az storage account create \
70-
--resource-group $RESOURCE_GROUP \
71-
--name $STORAGE_ACCOUNT \
72-
--location $REGION \
46+
--resource-group qsBatch \
47+
--name mybatchstorage \
48+
--location eastus2 \
7349
--sku Standard_LRS
7450
```
7551

7652
## Create a Batch account
7753

78-
Run the following [az batch account create](/cli/azure/batch/account#az-batch-account-create) command to create a Batch account in your resource group and link it with the storage account.
54+
Run the following [az batch account create](/cli/azure/batch/account#az-batch-account-create) command to create a Batch account named `mybatchaccount` in your resource group and link it with the `mybatchstorage` storage account.
7955

8056
```azurecli-interactive
81-
export BATCH_ACCOUNT="mybatchaccount$RANDOM_SUFFIX"
82-
8357
az batch account create \
84-
--name $BATCH_ACCOUNT \
85-
--storage-account $STORAGE_ACCOUNT \
86-
--resource-group $RESOURCE_GROUP \
87-
--location $REGION
58+
--name mybatchaccount \
59+
--storage-account mybatchstorage \
60+
--resource-group qsBatch \
61+
--location eastus2
8862
```
8963

9064
Sign in to the new Batch account by running the [az batch account login](/cli/azure/batch/account#az-batch-account-login) command. Once you authenticate your account with Batch, subsequent `az batch` commands in this session use this account context.
9165

9266
```azurecli-interactive
9367
az batch account login \
94-
--name $BATCH_ACCOUNT \
95-
--resource-group $RESOURCE_GROUP \
68+
--name mybatchaccount \
69+
--resource-group qsBatch \
9670
--shared-key-auth
9771
```
9872

9973
## Create a pool of compute nodes
10074

101-
Run the [az batch pool create](/cli/azure/batch/pool#az-batch-pool-create) command to create a pool of Linux compute nodes in your Batch account. The following example creates a pool that consists of two Standard_A1_v2 size VMs running Ubuntu 20.04 LTS OS. This node size offers a good balance of performance versus cost for this quickstart example.
75+
Run the [az batch pool create](/cli/azure/batch/pool#az-batch-pool-create) command to create a pool of Linux compute nodes in your Batch account. The following example creates a pool named `myPool` that consists of two Standard_A1_v2 size VMs running Ubuntu 20.04 LTS OS. This node size offers a good balance of performance versus cost for this quickstart example.
10276

10377
```azurecli-interactive
104-
export POOL_ID="myPool$RANDOM_SUFFIX"
105-
10678
az batch pool create \
107-
--id $POOL_ID \
79+
--id myPool \
10880
--image canonical:0001-com-ubuntu-server-focal:20_04-lts \
10981
--node-agent-sku-id "batch.node.ubuntu 20.04" \
11082
--target-dedicated-nodes 2 \
@@ -114,32 +86,20 @@ az batch pool create \
11486
Batch creates the pool immediately, but takes a few minutes to allocate and start the compute nodes. To see the pool status, use the [az batch pool show](/cli/azure/batch/pool#az-batch-pool-show) command. This command shows all the properties of the pool, and you can query for specific properties. The following command queries for the pool allocation state:
11587

11688
```azurecli-interactive
117-
az batch pool show --pool-id $POOL_ID \
118-
--query "{allocationState: allocationState}"
119-
```
120-
121-
Results:
122-
123-
<!-- expected_similarity=0.3 -->
124-
125-
```JSON
126-
{
127-
"allocationState": "resizing"
128-
}
89+
az batch pool show --pool-id myPool \
90+
--query "allocationState"
12991
```
13092

13193
While Batch allocates and starts the nodes, the pool is in the `resizing` state. You can create a job and tasks while the pool state is still `resizing`. The pool is ready to run tasks when the allocation state is `steady` and all the nodes are running.
13294

13395
## Create a job
13496

135-
Use the [az batch job create](/cli/azure/batch/job#az-batch-job-create) command to create a Batch job to run on your pool. A Batch job is a logical group of one or more tasks. The job includes settings common to the tasks, such as the pool to run on. The following example creates a job that initially has no tasks.
97+
Use the [az batch job create](/cli/azure/batch/job#az-batch-job-create) command to create a Batch job to run on your pool. A Batch job is a logical group of one or more tasks. The job includes settings common to the tasks, such as the pool to run on. The following example creates a job called `myJob` on `myPool` that initially has no tasks.
13698

13799
```azurecli-interactive
138-
export JOB_ID="myJob$RANDOM_SUFFIX"
139-
140100
az batch job create \
141-
--id $JOB_ID \
142-
--pool-id $POOL_ID
101+
--id myJob \
102+
--pool-id myPool
143103
```
144104

145105
## Create job tasks
@@ -153,22 +113,22 @@ for i in {1..4}
153113
do
154114
az batch task create \
155115
--task-id myTask$i \
156-
--job-id $JOB_ID \
116+
--job-id myJob \
157117
--command-line "/bin/bash -c 'printenv | grep AZ_BATCH; sleep 90s'"
158118
done
159119
```
160120

161-
Batch distributes the tasks to the compute nodes.
121+
The command output shows the settings for each task. Batch distributes the tasks to the compute nodes.
162122

163123
## View task status
164124

165-
After you create the tasks, Batch queues them to run on the pool. Once a node is available, a task runs on the node.
125+
After you create the task, Batch queues the task to run on the pool. Once a node is available, the task runs on the node.
166126

167127
Use the [az batch task show](/cli/azure/batch/task#az-batch-task-show) command to view the status of Batch tasks. The following example shows details about the status of `myTask1`:
168128

169129
```azurecli-interactive
170130
az batch task show \
171-
--job-id $JOB_ID \
131+
--job-id myJob \
172132
--task-id myTask1
173133
```
174134

@@ -179,39 +139,29 @@ The command output includes many details. For example, an `exitCode` of `0` indi
179139
Use the [az batch task file list](/cli/azure/batch/task#az-batch-task-file-show) command to list the files a task created on a node. The following command lists the files that `myTask1` created:
180140

181141
```azurecli-interactive
182-
# Wait for task to complete before downloading output
183-
echo "Waiting for task to complete..."
184-
while true; do
185-
STATUS=$(az batch task show --job-id $JOB_ID --task-id myTask1 --query "state" -o tsv)
186-
if [ "$STATUS" == "running" ]; then
187-
break
188-
fi
189-
sleep 10
190-
done
191-
192-
az batch task file list --job-id $JOB_ID --task-id myTask1 --output table
142+
az batch task file list \
143+
--job-id myJob \
144+
--task-id myTask1 \
145+
--output table
193146
```
194147

195148
Results are similar to the following output:
196149

197-
Results:
198-
199-
<!-- expected_similarity=0.3 -->
200-
201150
```output
202151
Name URL Is Directory Content Length
203152
---------- ---------------------------------------------------------------------------------------- -------------- ----------------
204153
stdout.txt https://mybatchaccount.eastus2.batch.azure.com/jobs/myJob/tasks/myTask1/files/stdout.txt False 695
205154
certs https://mybatchaccount.eastus2.batch.azure.com/jobs/myJob/tasks/myTask1/files/certs True
206155
wd https://mybatchaccount.eastus2.batch.azure.com/jobs/myJob/tasks/myTask1/files/wd True
207156
stderr.txt https://mybatchaccount.eastus2.batch.azure.com/jobs/myJob/tasks/myTask1/files/stderr.txt False 0
157+
208158
```
209159

210160
The [az batch task file download](/cli/azure/batch/task#az-batch-task-file-download) command downloads output files to a local directory. Run the following example to download the *stdout.txt* file:
211161

212162
```azurecli-interactive
213163
az batch task file download \
214-
--job-id $JOB_ID \
164+
--job-id myJob \
215165
--task-id myTask1 \
216166
--file-path stdout.txt \
217167
--destination ./stdout.txt
@@ -237,9 +187,25 @@ AZ_BATCH_ACCOUNT_NAME=mybatchaccount
237187
AZ_BATCH_TASK_USER_IDENTITY=PoolNonAdmin
238188
```
239189

190+
## Clean up resources
191+
192+
If you want to continue with Batch tutorials and samples, you can use the Batch account and linked storage account that you created in this quickstart. There's no charge for the Batch account itself.
193+
194+
Pools and nodes incur charges while the nodes are running, even if they aren't running jobs. When you no longer need a pool, use the [az batch pool delete](/cli/azure/batch/pool#az-batch-pool-delete) command to delete it. Deleting a pool deletes all task output on the nodes, and the nodes themselves.
195+
196+
```azurecli-interactive
197+
az batch pool delete --pool-id myPool
198+
```
199+
200+
When you no longer need any of the resources you created for this quickstart, you can use the [az group delete](/cli/azure/group#az-group-delete) command to delete the resource group and all its resources. To delete the resource group and the storage account, Batch account, node pools, and all related resources, run the following command:
201+
202+
```azurecli-interactive
203+
az group delete --name qsBatch
204+
```
205+
240206
## Next steps
241207

242208
In this quickstart, you created a Batch account and pool, created and ran a Batch job and tasks, and viewed task output from the nodes. Now that you understand the key concepts of the Batch service, you're ready to use Batch with more realistic, larger scale workloads. To learn more about Azure Batch, continue to the Azure Batch tutorials.
243209

244210
> [!div class="nextstepaction"]
245-
> [Tutorial: Run a parallel workload with Azure Batch](./tutorial-parallel-python.md)
211+
> [Tutorial: Run a parallel workload with Azure Batch](./tutorial-parallel-python.md)

0 commit comments

Comments
 (0)