简体   繁体   English

如果缺少本地node_modules文件夹,DevOps将运行npm install

[英]DevOps run npm install if local node_modules folder is missing

I am using DevOps build definition to bundle an AngularJs app. 我正在使用DevOps构建定义来捆绑AngularJs应用。 Is there a way to check if the local node_modules exists and if it doesn't exist run the npm install command before the bundling process takes place? 有没有办法检查本地node_modules是否存在以及是否不存在,请在捆绑过程发生之前运行npm install命令?

You can add a script task to check if the folder exists and then set a variable. 您可以添加脚本任务来检查文件夹是否存在,然后设置一个变量。 For the npm task, you need to set the condition to run. 对于npm任务,您需要设置运行条件。 Please refer to following content. 请参考以下内容。

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: 'if [ -d "node_modules" ]; then
            echo "##vso[task.setVariable variable=FOLDEREXISTS]true"
      fi'

- task: Npm@1
  inputs:
    command: 'install'
    condition: eq(variables.FOLDEREXISTS, 'true')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM