I have created a build pipeline for my angular and web api. It has 3 jobs. However every time it does npm install and dotnet.exe. Do we need this every time or can we cache this. If we can cache this how can I add this cache step? Below is my yaml script:
variables:
- name: solution
value: 'MyProject.sln'
- name: buildPlatform
value: 'Any CPU'
- name: buildConfiguration
value: 'Release'
stages:
- stage: StartAzVMAgent
jobs:
- job: MsHostedAgentJobStartAzVM
timeoutInMinutes: 0
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI@2
displayName: Azure CLI
inputs:
azureSubscription: "Az-DevOps-AgentManager"
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show
az vm start --name Deployment-Agent --no-wait --resource-group Rg_Deployment
- stage: __default
jobs:
- job: Job
timeoutInMinutes: 0
pool:
name: Default
demands:
- Use_for -equals klcloud
steps:
# - task: Npm@1
# displayName: Install Node dependencies (packages)
# inputs:
# command: install
# workingDir: 'MyProject.WebUI\MyApp'
- task: Npm@1
displayName: Install Node dependencies (packages)
inputs:
command: custom
customCommand: install --save --legacy-peer-deps
workingDir: 'MyProject.WebUI\MyApp'
- task: Npm@1
displayName: Install Node dependencies (packages)
inputs:
command: custom
customCommand: install sweetalert2 file-saver
workingDir: 'MyProject.WebUI\MyApp'
- task: CmdLine@2
displayName: Building Client App
inputs:
script: node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --configuration production --aot --output-hashing=all
workingDirectory: 'MyProject.WebUI\MyApp'
- task: CopyFiles@2
displayName: 'Copy Client Project'
inputs:
Contents: |
MyProject.WebUI\MyApp\dist\**
TargetFolder: '$(build.artifactstagingdirectory)/client'
flattenFolders: false
CleanTargetFolder: true
- task: UseDotNet@2
displayName: Use .NET 6.0
inputs:
packageType: 'sdk'
version: '6.0.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
zipAfterPublish: true
arguments: '--output $(build.artifactstagingdirectory)/api'
- task: CmdLine@2
displayName: Create EF Scripts
inputs:
script: |
dotnet ef migrations add MyDb_082021 -c MyProjectDbcontext
dotnet ef migrations script --idempotent --output migrations.sql --project MyProject.Persistence/MyProject.Persistence.csproj --context MyProjectDbContext
- task: CopyFiles@2
displayName: 'Copy EF Scripts to Staging'
inputs:
Contents: "**\\migrations.sql \n"
TargetFolder: '$(build.artifactstagingdirectory)'
flattenFolders: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: StoptAzVMAgent
jobs:
- job: MsHostedAgentJobStopAZVm
timeoutInMinutes: 0
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI@2
displayName: Azure CLI
inputs:
azureSubscription: "Az-DevOps-AgentManager"
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show
az vm deallocate --name Deployment-Agent --no-wait --resource-group Rg_Deployment
Please let me know in case if you need any additional information