|
| 1 | +--- |
| 2 | +title: View task run logs - Tasks |
| 3 | +description: How to view and manage run logs generated by ACR Tasks. |
| 4 | +ms.topic: article |
| 5 | +ms.date: 03/09/2020 |
| 6 | +--- |
| 7 | + |
| 8 | +# View and manage task run logs |
| 9 | + |
| 10 | +Each task run in [Azure Container Registry tasks](container-registry-tasks-overview.md) generates log output that you can inspect to determine whether the task steps ran successfully. This article explains how to view and manage these run logs. |
| 11 | + |
| 12 | +## View streamed logs |
| 13 | + |
| 14 | +Tasks that you trigger manually stream log output directly to the console. For example, when you trigger a task manually by using the [az acr build](/cli/azure/acr#az-acr-build), [az acr run](/cli/azure/acr#az-acr-run), or [az acr task run](/cli/azure/acr/task#az-acr-task-run) command, log output is streamed to the console. |
| 15 | + |
| 16 | +The following sample [az acr run](/cli/azure/acr#az-acr-run) command manually triggers running a container pulled from a registry: |
| 17 | + |
| 18 | +```azurecli |
| 19 | +az acr run --registry mycontainerregistry1220 \ |
| 20 | + --cmd '$Registry/samples/hello-world:v1' /dev/null |
| 21 | +``` |
| 22 | + |
| 23 | +Streamed log for run *cf4*: |
| 24 | + |
| 25 | +```console |
| 26 | +Queued a run with ID: cf4 |
| 27 | +Waiting for an agent... |
| 28 | +2020/03/09 20:30:10 Alias support enabled for version >= 1.1.0, please see https://aka.ms/acr/tasks/task-aliases for more information. |
| 29 | +2020/03/09 20:30:10 Creating Docker network: acb_default_network, driver: 'bridge' |
| 30 | +2020/03/09 20:30:10 Successfully set up Docker network: acb_default_network |
| 31 | +2020/03/09 20:30:10 Setting up Docker configuration... |
| 32 | +2020/03/09 20:30:11 Successfully set up Docker configuration |
| 33 | +2020/03/09 20:30:11 Logging in to registry: mycontainerregistry1220azurecr.io |
| 34 | +2020/03/09 20:30:12 Successfully logged into mycontainerregistry1220azurecr.io |
| 35 | +2020/03/09 20:30:12 Executing step ID: acb_step_0. Timeout(sec): 600, Working directory: '', Network: 'acb_default_network' |
| 36 | +2020/03/09 20:30:12 Launching container with name: acb_step_0 |
| 37 | +Unable to find image 'mycontainerregistry1220azurecr.io/samples/hello-world:v1' locally |
| 38 | +v1: Pulling from samples/hello-world |
| 39 | +Digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e888a |
| 40 | +Status: Downloaded newer image for mycontainerregistry1220azurecr.io/samples/hello-world:v1 |
| 41 | + |
| 42 | +Hello from Docker! |
| 43 | +This message shows that your installation appears to be working correctly. |
| 44 | +[...] |
| 45 | + |
| 46 | +2020/03/09 20:30:13 Successfully executed container: acb_step_0 |
| 47 | +2020/03/09 20:30:13 Step ID: acb_step_0 marked as successful (elapsed time in seconds: 1.180081) |
| 48 | + |
| 49 | +Run ID: cf4 was successful after 5s |
| 50 | +``` |
| 51 | + |
| 52 | +## View stored logs |
| 53 | + |
| 54 | +Azure Container Registry stores run logs for all tasks. You can view stored run logs in the Azure portal, or use the [az acr task logs](/cli/azure/acr/task#az-acr-task-logs) command. |
| 55 | + |
| 56 | +If a task is automatically triggered, for example by a source code update, accessing the stored logs is the *only* way to view the run logs. Automatic task triggers include source code commits or pull requests, base image updates, or timer triggers. |
| 57 | + |
| 58 | +To view run logs in the portal: |
| 59 | + |
| 60 | +1. Navigate to your container registry. |
| 61 | +1. In **Services**, select **Tasks** > **Runs**. |
| 62 | +1. Select a **Run Id** to view the run status and run logs. The log contains the same information as a streamed log, if one is generated. |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +In the Azure CLI, run [az acr task logs](/cli/azure/acr/task#az-acr-task-logs) and specify a run ID, a task name, or a specific image built by the task. If a task name is specified, the command shows the log for the last created run. For example, specify a run ID to view the log for that run: |
| 67 | + |
| 68 | +```azurecli |
| 69 | +az acr task logs --registry mycontainerregistry1220 \ |
| 70 | + --run-id cf4 |
| 71 | +``` |
| 72 | +The output shows the specified run log. |
| 73 | + |
| 74 | +## Log retention |
| 75 | + |
| 76 | +By default, data and logs for task runs in a registry are retained for 30 days. After that time, records are automatically purged. |
| 77 | + |
| 78 | +If you want Azure Container Registry to archive the data for a task run, enable archiving using the [az acr task update-run](/cli/azure/acr/task#az-acr-task-update-run) command. The following example enables archiving for the task run *cf4*: |
| 79 | + |
| 80 | +```azurecli |
| 81 | +az acr task update-run \ |
| 82 | + --registry mycontainerregistry1220 \ |
| 83 | + --run-id cf4 --no-archive false |
| 84 | +``` |
| 85 | + |
| 86 | +## Alternative log storage |
| 87 | + |
| 88 | +You might want to store task run logs on a local file system or use an alternative archiving solution such as Azure Storage. |
| 89 | + |
| 90 | +For example, create a local *tasklogs* directory, and redirect the output of [az acr task logs](/cli/azure/acr/task#az-acr-task-logs) to a local file: |
| 91 | + |
| 92 | +```azurecli |
| 93 | +mkdir ~/tasklogs |
| 94 | +
|
| 95 | +az acr task logs --registry mycontainerregistry1220 \ |
| 96 | + --run-id cf4 > ~/tasklogs/cf4.log |
| 97 | +``` |
| 98 | + |
| 99 | +You can save local log files to Azure Storage. For example, use the [Azure CLI](../storage/blobs/storage-quickstart-blobs-cli.md), the [Azure portal](../storage/blobs/storage-quickstart-blobs-portal.md), or other methods to upload files to a storage account. |
| 100 | + |
| 101 | + |
| 102 | +## Next steps |
| 103 | + |
| 104 | +* Learn more about [Azure Container Registry Tasks](container-registry-tasks-overview.md) |
| 105 | + |
| 106 | +<!-- LINKS - External --> |
| 107 | +[base-alpine]: https://hub.docker.com/_/alpine/ |
| 108 | +[base-dotnet]: https://hub.docker.com/r/microsoft/dotnet/ |
| 109 | +[base-node]: https://hub.docker.com/_/node/ |
| 110 | +[base-windows]: https://hub.docker.com/r/microsoft/nanoserver/ |
| 111 | +[sample-archive]: https://github.com/Azure-Samples/acr-build-helloworld-node/archive/master.zip |
| 112 | +[terms-of-use]: https://azure.microsoft.com/support/legal/preview-supplemental-terms/ |
| 113 | + |
| 114 | +<!-- LINKS - Internal --> |
| 115 | +[azure-cli]: /cli/azure/install-azure-cli |
| 116 | +[az-acr-build]: /cli/azure/acr#az-acr-build |
| 117 | +[az-acr-pack-build]: /cli/azure/acr/pack#az-acr-pack-build |
| 118 | +[az-acr-task]: /cli/azure/acr/task |
| 119 | +[az-acr-task-create]: /cli/azure/acr/task#az-acr-task-create |
| 120 | +[az-acr-task-run]: /cli/azure/acr/task#az-acr-task-run |
| 121 | +[az-acr-task-update]: /cli/azure/acr/task#az-acr-task-update |
| 122 | +[az-login]: /cli/azure/reference-index#az-login |
| 123 | +[az-login-service-principal]: /cli/azure/authenticate-azure-cli |
| 124 | + |
| 125 | +<!-- IMAGES --> |
| 126 | +[quick-build-01-fork]: ./media/container-registry-tutorial-quick-build/quick-build-01-fork.png |
| 127 | +[quick-build-02-browser]: ./media/container-registry-tutorial-quick-build/quick-build-02-browser.png |
0 commit comments