我是 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'
正如你所看到的,npm 花费了大量时间,我猜会有缓存机制,但我不知道如何正确更改我的 YAMl 文件,完全删除 npm 安装步骤还是不?
管道缓存可以通过允许在以后的运行中重用一次运行的输出或下载的依赖项来帮助减少构建时间,从而减少或避免再次重新创建或重新下载相同文件的成本。因此,您可以通过引用
Node.js/npm来缓存
npm modules
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
此外,自托管代理让您可以更好地控制安装构建和部署所需的依赖软件。此外,机器级缓存和配置在每次运行中都会保留,这可以提高速度。因此,您可以选择在管道中使用自托管代理。
对于任务的任何变化,我遇到了同样的问题:Npm@1。
对于 npm install 命令,任务日志显示:“Done in 4.9s”,但管道继续运行 3 分钟左右,直到记录:“Finishing: install”。
对我来说,Npm@1 任务的内部工作在完成后似乎没有正确退出该进程,并且在某个点(180 秒)遇到超时并将该步骤标记为已完成。