我是 YAMl 文件和 ci/cd 的新手,最近我加入了一个有 ci/cd 管道的项目,当我们运行管道构建时大约需要 25-30 分钟。应用程序本身并不是那么巨大,我想说它是中型整体应用程序。下面你可以看到我的 YAML 文件
trigger:
- development
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Test'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: Npm@1
inputs:
command: 'install'
workingDir: 'frontend'
- task: Npm@1
inputs:
command: 'custom'
workingDir: 'frontend'
customCommand: 'run build-test'
- task: Npm@1
inputs:
command: 'install'
workingDir: 'admin-frontend'
- task: Npm@1
inputs:
command: 'custom'
workingDir: 'admin-frontend'
customCommand: 'run build-test'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArchitecture: 'x64'
createLogFile: true
logFileVerbosity: 'diagnostic'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifact: 'Web-Project-Test'
Also take a look the picture of the particular step times
正如你所看到的,npm 花费了大量时间,我猜会有缓存机制,但我不知道如何正确更改我的 YAMl 文件,完全删除 npm 安装步骤还是不删除?
管道缓存 https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops可以通过允许在以后的运行中重复使用一次运行的输出或下载的依赖项来帮助缩短构建时间,从而减少或避免再次重新创建或重新下载相同文件的成本。这样你就可以缓存npm modules
参考Node.js/npm https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm
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)
displayName: Cache npm
- script: npm ci
此外,使您能够更好地控制安装构建和部署所需的依赖软件。此外,机器级缓存和配置在每次运行中都会保留,这可以提高速度。因此你可以选择使用在管道中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)