Skip to content

Commit 0a091db

Browse files
authored
Merge pull request #89309 from dlepow/acralias
[ACR] Task YAML ref update to v1.1.0
2 parents f8cfb8d + 5d6bfd6 commit 0a091db

File tree

1 file changed

+120
-26
lines changed

1 file changed

+120
-26
lines changed

articles/container-registry/container-registry-tasks-reference-yaml.md

Lines changed: 120 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ manager: gwallace
77

88
ms.service: container-registry
99
ms.topic: article
10-
ms.date: 07/12/2019
10+
ms.date: 10/23/2019
1111
ms.author: danlep
1212
---
1313

@@ -124,7 +124,7 @@ Build a container image. The `build` step type represents a multi-tenant, secure
124124
### Syntax: build
125125

126126
```yml
127-
version: v1.0.0
127+
version: v1.1.0
128128
steps:
129129
- [build]: -t [imageName]:[tag] -f [Dockerfile] [context]
130130
[property]: [value]
@@ -179,9 +179,9 @@ az acr run -f build-hello-world.yaml https://github.com/AzureCR/acr-tasks-sample
179179
#### Build image - context in subdirectory
180180

181181
```yml
182-
version: v1.0.0
182+
version: v1.1.0
183183
steps:
184-
- build: -t {{.Run.Registry}}/hello-world -f hello-world.dockerfile ./subDirectory
184+
- build: -t $Registry/hello-world -f hello-world.dockerfile ./subDirectory
185185
```
186186

187187
## push
@@ -193,21 +193,21 @@ Push one or more built or retagged images to a container registry. Supports push
193193
The `push` step type supports a collection of images. YAML collection syntax supports inline and nested formats. Pushing a single image is typically represented using inline syntax:
194194

195195
```yml
196-
version: v1.0.0
196+
version: v1.1.0
197197
steps:
198198
# Inline YAML collection syntax
199-
- push: ["{{.Run.Registry}}/hello-world:{{.Run.ID}}"]
199+
- push: ["$Registry/hello-world:$ID"]
200200
```
201201

202202
For increased readability, use nested syntax when pushing multiple images:
203203

204204
```yml
205-
version: v1.0.0
205+
version: v1.1.0
206206
steps:
207207
# Nested YAML collection syntax
208208
- push:
209-
- {{.Run.Registry}}/hello-world:{{.Run.ID}}
210-
- {{.Run.Registry}}/hello-world:latest
209+
- $Registry/hello-world:$ID
210+
- $Registry/hello-world:latest
211211
```
212212

213213
### Properties: push
@@ -250,7 +250,7 @@ The `cmd` step type runs a container.
250250
### Syntax: cmd
251251

252252
```yml
253-
version: v1.0.0
253+
version: v1.1.0
254254
steps:
255255
- [cmd]: [containerImage]:[tag (optional)] [cmdParameters to the image]
256256
```
@@ -326,33 +326,31 @@ az acr run -f bash-echo-3.yaml https://github.com/Azure-Samples/acr-tasks.git
326326
The `cmd` step type references images using the standard `docker run` format. Images not prefaced with a registry are assumed to originate from docker.io. The previous example could equally be represented as:
327327

328328
```yml
329-
version: v1.0.0
329+
version: v1.1.0
330330
steps:
331331
- cmd: docker.io/bash:3.0 echo hello world
332332
```
333333

334334
By using the standard `docker run` image reference convention, `cmd` can run images from any private registry or the public Docker Hub. If you're referencing images in the same registry in which ACR Task is executing, you don't need to specify any registry credentials.
335335

336-
* Run an image that's from an Azure container registry
337-
338-
Replace `[myregistry]` with the name of your registry:
336+
* Run an image that's from an Azure container registry. The following example assumes you have a registry named `myregistry`, and a custom image `myimage:mytag`.
339337

340338
```yml
341-
version: v1.0.0
339+
version: v1.1.0
342340
steps:
343-
- cmd: [myregistry].azurecr.io/bash:3.0 echo hello world
341+
- cmd: myregistry.azurecr.io/myimage:mytag
344342
```
345343

346-
* Generalize the registry reference with a Run variable
344+
* Generalize the registry reference with a Run variable or alias
347345

348-
Instead of hard-coding your registry name in an `acr-task.yaml` file, you can make it more portable by using a [Run variable](#run-variables). The `Run.Registry` variable expands at runtime to the name of the registry in which the task is executing.
346+
Instead of hard-coding your registry name in an `acr-task.yaml` file, you can make it more portable by using a [Run variable](#run-variables) or [alias](#aliases). The `Run.Registry` variable or `$Registry` alias expands at runtime to the name of the registry in which the task is executing.
349347

350-
To generalize the preceding task so that it works in any Azure container registry, reference the [Run.Registry](#runregistry) variable in the image name:
348+
For example, to generalize the preceding task so that it works in any Azure container registry, reference the $Registry variable in the image name:
351349

352350
```yml
353-
version: v1.0.0
351+
version: v1.1.0
354352
steps:
355-
- cmd: {{.Run.Registry}}/bash:3.0 echo hello world
353+
- cmd: $Registry/myimage:mytag
356354
```
357355

358356
## Task step properties
@@ -447,31 +445,50 @@ az acr run -f when-parallel-dependent.yaml https://github.com/Azure-Samples/acr-
447445
ACR Tasks includes a default set of variables that are available to task steps when they execute. These variables can be accessed by using the format `{{.Run.VariableName}}`, where `VariableName` is one of the following:
448446

449447
* `Run.ID`
448+
* `Run.SharedVolume`
450449
* `Run.Registry`
450+
* `Run.RegistryName`
451451
* `Run.Date`
452+
* `Run.OS`
453+
* `Run.Architecture`
452454
* `Run.Commit`
453455
* `Run.Branch`
456+
* `Run.TaskName`
457+
458+
The variable names are generally self-explanatory. Details follows for commonly used variables. As of YAML version `v1.1.0`, you can use an abbreviated, predefined [task alias](#aliases) in place of most run variables. For example, in place of `{{.Run.Registry}}`, use the `$Registry` alias.
454459

455460
### Run.ID
456461

457-
Each Run, through `az acr run`, or trigger based execution of tasks created through `az acr task create` have a unique ID. The ID represents the Run currently being executed.
462+
Each Run, through `az acr run`, or trigger based execution of tasks created through `az acr task create`, has a unique ID. The ID represents the Run currently being executed.
458463

459464
Typically used for a uniquely tagging an image:
460465

461466
```yml
462-
version: v1.0.0
467+
version: v1.1.0
463468
steps:
464-
- build: -t {{.Run.Registry}}/hello-world:{{.Run.ID}} .
469+
- build: -t $Registry/hello-world:$ID .
465470
```
466471

467472
### Run.Registry
468473

469474
The fully qualified server name of the registry. Typically used to generically reference the registry where the task is being run.
470475

471476
```yml
472-
version: v1.0.0
477+
version: v1.1.0
478+
steps:
479+
- build: -t $Registry/hello-world:$ID .
480+
```
481+
482+
### Run.RegistryName
483+
484+
The name of the container registry. Typically used in task steps that don't require a fully qualified server name, for example, `cmd` steps that run Azure CLI commands on registries.
485+
486+
```yml
487+
version 1.1.0
473488
steps:
474-
- build: -t {{.Run.Registry}}/hello-world:{{.Run.ID}} .
489+
# List repositories in registry
490+
- cmd: az login --identity
491+
- cmd: az acr repository list --name $RegistryName
475492
```
476493

477494
### Run.Date
@@ -486,12 +503,89 @@ For a task triggered by a commit to a GitHub repository, the commit identifier.
486503

487504
For a task triggered by a commit to a GitHub repository, the branch name.
488505

506+
## Aliases
507+
508+
As of `v1.1.0`, ACR Tasks supports aliases that are available to task steps when they execute. Aliases are similar in concept to aliases (command shortcuts) supported in bash and some other command shells.
509+
510+
With an alias, you can launch any command or group of commands (including options and filenames) by entering a single word.
511+
512+
ACR Tasks supports several predefined aliases and also custom aliases you create.
513+
514+
### Predefined aliases
515+
516+
The following task aliases are available to use in place of [run variables](#run-variables):
517+
518+
| Alias | Run variable |
519+
| ----- | ------------ |
520+
| `ID` | `Run.ID` |
521+
| `SharedVolume` | `Run.SharedVolume` |
522+
| `Registry` | `Run.Registry` |
523+
| `RegistryName` | `Run.RegistryName` |
524+
| `Date` | `Run.Date` |
525+
| `OS` | `Run.OS` |
526+
| `Architecture` | `Run.Architecture` |
527+
| `Commit` | `Run.Commit` |
528+
| `Branch` | `Run.Branch` |
529+
530+
In task steps, precede an alias with the `$` directive, as in this example:
531+
532+
```yaml
533+
version: v1.1.0
534+
steps:
535+
- build: -t $Registry/hello-world:$ID -f hello-world.dockerfile .
536+
```
537+
538+
### Image aliases
539+
540+
Each of the following aliases points to a stable image in Microsoft Container Registry (MCR). You can refer to each of them in the `cmd` section of a Task file without using a directive.
541+
542+
| Alias | Image |
543+
| ----- | ----- |
544+
| `acr` | `mcr.microsoft.com/acr/acr-cli:0.1` |
545+
| `az` | `mcr.microsoft.com/acr/azure-cli:d0725bc` |
546+
| `bash` | `mcr.microsoft.com/acr/bash:d0725bc` |
547+
| `curl` | `mcr.microsoft.com/acr/curl:d0725bc` |
548+
549+
The following example task uses several aliases to [purge](container-registry-auto-purge.md) image tags older than 7 days in the repo `samples/hello-world` in the run registry:
550+
551+
```yaml
552+
version: v1.1.0
553+
steps:
554+
- cmd: acr tag list --registry $RegistryName --repository samples/hello-world
555+
- cmd: acr purge --registry $RegistryName --filter samples/hello-world:.* --ago 7d
556+
```
557+
558+
### Custom alias
559+
560+
Define a custom alias in your YAML file and use it as shown in the following example. An alias can contain only alphanumeric characters. The default directive to expand an alias is the `$` character.
561+
562+
```yml
563+
version: v1.1.0
564+
alias:
565+
values:
566+
repo: myrepo
567+
steps:
568+
- build: -t $Registry/$repo/hello-world:$ID -f Dockerfile .
569+
```
570+
571+
You can link to a remote or local YAML file for custom alias definitions. The following example links to a YAML file in Azure blob storage:
572+
573+
```yml
574+
version: v1.1.0
575+
alias:
576+
src: # link to local or remote custom alias files
577+
- 'https://link/to/blob/remoteAliases.yml?readSasToken'
578+
[...]
579+
```
580+
489581
## Next steps
490582

491583
For an overview of multi-step tasks, see the [Run multi-step build, test, and patch tasks in ACR Tasks](container-registry-tasks-multi-step.md).
492584

493585
For single-step builds, see the [ACR Tasks overview](container-registry-tasks-overview.md).
494586

587+
588+
495589
<!-- IMAGES -->
496590

497591
<!-- LINKS - External -->

0 commit comments

Comments
 (0)