Exam AZ-400 All QuestionsBrowse all questions from this exam
Question 324

DRAG DROP -

You have an Azure DevOps pipeline that is used to deploy a Node.js app.

You need to ensure that the dependencies are cached between builds.

How should you configure the deployment YAML? To answer, drag the appropriate values to the correct targets. Each value may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.

NOTE: Each correct selection is worth one point.

    Correct Answer:

Discussion
basiltomato

I think we are overthinking this one and it's typical MS confusing question. They probably want similar answer as on the given link https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#conditioning-on-cache-restoration So basically install dependencies (npm install) IF cache NOT restored. Therefore: - npm install - ne(variables.CACHE_RESTORED, 'true') The build.sh would be below above script

mfawew223

To support this, the comments have come to 2 different answers, but one doesnt make sense to design a pipeline that way. The 2 answers can be described as either "if npm is cached, then run build.sh" or "if npm is not cached, install npm". Whats going to happen if the pipeline isnt cached? in the first answer, the pipeline would just stop/fail if npm isnt cached. So how would you have npm cached in the first place? For the 2nd answer, what happens if npm isnt cached? npm gets installed, then we move to the next step. The step being shown isnt a build step. its a step that ensures that npm is installed BEFORE the build.sh uses npm in another step. The only thing this step should be doing is ensuring npm is installed for the rest of the pipeline. Thus, basiltomato's answer is the correct one

Hillah

You need to ensure that the dependencies are cached between builds. Therefore, we assume that npm is already installed, we only need to cache at build Hence - build.sh - Eq(variables.CACHE_RESTORED, 'true')

wiokito

i think it should be : - npm install - ne(variables.CACHE_RESTORED, 'true') https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#conditioning-on-cache-restoration

wiokito

i edit my answer: the goal here is to "ensure" caching so the solution is: - build.sh - Eq(variables.CACHE_RESTORED, 'true')

crymo99

I believe given answer is correct. - build.sh - ne(variables.CACHE_RESTORED, 'true')

gabo

This is incorrect. You are building the app if cache is not restored which will cause the pipeline to fail.

zellck

1. build.sh 2. ne(variables.CACHE_RESTORED, 'true') https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#conditioning-on-cache-restoration

gabo

This is incorrect. You are building the app if cache is not restored which will cause the pipeline to fail.

mrg998

Answer is: Npm install - install Eq(variables.CACHE_RESTORED, 'true') - only if cache has been restored https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#conditioning-on-cache-restoration

AlexeyG

variables: NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages steps: - task: Cache@2 inputs: key: 'nuget | "$(Agent.OS)" | $(Build.SourcesDirectory)/**/packages.lock.json' restoreKeys: | nuget | "$(Agent.OS)" nuget path: $(NUGET_PACKAGES) displayName: Cache NuGet packages Answer on exam $(Build.SourcesDirectory)/**/packages.lock.json' "$(Agent.OS)" $(NUGET_PACKAGES) got this in 02 March 2023 exams. scored 870 marks.

4b31a3a

The 3 ... means that there is more of the pipline that is not shown, if we presume the parts of the pipline not shown are to do with the deployment we can deduce that we are dealing with the part of the pipeline that handles package installation. Thjere for the answer is - npm install - ne(variables.CACHE_RESTORED, 'true')

Dats1987

In some scenarios, the successful restoration of the cache should cause a different set of steps to be run. For example, a step that installs dependencies can be skipped if the cache was restored. This is possible using the cacheHitVar task input. Setting this input to the name of an environment variable will cause the variable to be set to true when there's a cache hit, inexact on a restore key cache hit, otherwise it will be set to false. This variable can then be referenced in a step condition or from within a script. In the following example, the install-deps.sh step is skipped when the cache is restored: steps: - task: Cache@2 inputs: key: mykey | mylockfile restoreKeys: mykey path: $(Pipeline.Workspace)/mycache cacheHitVar: CACHE_RESTORED - script: install-deps.sh condition: ne(variables.CACHE_RESTORED, 'true') - script: build.sh

3arle

at first should be npm install, then build https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#conditioning-on-cache-restoration

sondrex

Script: npm install Condition: ne(variables.CACHE_RESTORED, 'true')

4bd3116

The Answer is correct: variables: npm_config_cache: $(Pipeline.Workspace)/.npm steps: - task: Cache@2 inputs: key: 'npm | "$(Agent.OS)" | package-lock.json' restoreKeys: | npm | "$(Agent.OS)" path: $(npm_config_cache) cacheHitVar: CACHE_RESTORED - script: ./build.sh condition: ne(variables.CACHE_RESTORED, 'true')

Kalaisuran

https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops

varinder82

Final Answer after going through below comments - npm install - ne(variables.CACHE_RESTORED, 'true')

CirusD

trigger: - master pool: vmImage: 'ubuntu-latest' steps: - checkout: self - task: Cache@2 inputs: key: 'npm | package-lock.json' path: $(Pipeline.Workspace)/.npm cacheHitVar: CACHE_RESTORED - script: npm ci displayName: 'npm ci' condition: ne(variables.CACHE_RESTORED, 'true') - script: npm run build displayName: 'npm build'

gabo

If you choose to run the build.sh script, then that should run only if Cache is successfully restored, so choose eq(variables.CACHE_RESTORED, 'true')

gabo

On the other hand if you choose to run npm install, then it should run only if Cache is not restored, so choose ne(variables.CACHE_RESTORED, 'true')