AZ-400 · Question #590
Hotspot Question You have an Azure subscription that contains Azure DevOps build pipelines. You need to implement pipeline caching by using the cache task. How should you complete the YAML definition?
The correct answer is 'yarn' | "$(Agent.OS)" | yarn.lock': key:; $(YARN_CACHE_FOLDER): path:. This question tests knowledge of implementing pipeline caching in Azure DevOps using the Cache task in a YAML pipeline definition. The Cache task reduces build time by reusing files from previous runs when the cache key hasn't changed.
Question
Exhibit
Answer Area
- 'yarn' | "$(Agent.OS)" | yarn.lock'key:element:item:key:restoreKeys:
- $(YARN_CACHE_FOLDER)path:directory:folder:location:path:
Explanation
This question tests knowledge of implementing pipeline caching in Azure DevOps using the Cache task in a YAML pipeline definition. The Cache task reduces build time by reusing files from previous runs when the cache key hasn't changed.
Approach. The correct YAML structure for the Cache task requires 'task: Cache@2' as the task identifier with version 2, followed by 'inputs:' containing three key properties: 'key' (a unique identifier for the cache, typically using a hash of dependency files like package-lock.json), 'restoreKeys' (fallback keys if the exact key isn't found), and 'path' (the directory to cache, such as $(npm_config_cache) or node_modules). The key is usually defined using a pipe-delimited string combining the OS, a literal string, and a file hash like '"npm" | "$(Agent.OS)" | package-lock.json' to ensure cache validity across different environments and dependency changes.
Concept tested. Azure DevOps pipeline caching using the Cache@2 task in YAML pipelines, including proper syntax for cache key definition, restore keys, and cache path configuration to optimize build performance.
Reference. https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops
Topics
Community Discussion
No community discussion yet for this question.
