如何在Azure CI管道中手动添加“脚本”?

时间:2020-11-03 20:42:32

标签: azure-devops azure-pipelines

我在BitBucket中有一个node.js / typescript / angular项目,我想在Azure Devops上为其创建生成(CI)管道。我使用经典的编辑器创建了管道(以下原因),并尝试添加以下任务/步骤:

  1. npm install @ types / node @ 8.10.52
  2. ng构建(ng是有角的)

classic editor pipeline

如果要使用YAML配置,则生成的YAML文件看起来像下面的以下文件,那么如何在经典编辑器中的Node任务之后手动创建“脚本”?我只有将“ npm”添加为任务的选项,这就是为什么我添加了3个npm任务(如上图所示)以及3个单独的自定义命令来模仿下面的YML文件中的步骤配置的原因。使用自定义命令可以做到这一点吗?

通过YAML配置的YAML文件npm /角度表示:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install -g @angular/cli
    npm install
    ng build --prod
  displayName: 'npm install and build'

为什么我要使用经典编辑器:

当我尝试保存YAML配置管道时,出现了“来自bitbucket的错误:出了点问题”错误,根据我在Atlassian论坛上发现的内容,这似乎是写权限问题。

所以我最终只使用了经典的管道编辑器,因此我能够选择特定的分支(即dev)而不是master(产品)分支。

1 个答案:

答案 0 :(得分:1)

我处理此问题的方法是将脚本添加到您的package.json

"scripts": {
    "ng": "ng",
    "build": "ng build",
    "build-prod": "ng build --configuration=production"
    "build-dev": "ng build --configuration=dev"
},
 ...

然后,您只需从自定义NPM任务中调用运行脚本:

enter image description here

或者您可以选择在任务上调用run-script build --prod,因为您可以在任务上传递参数。

YAML中提供了相同的步骤,看起来像这样:

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install node.js'
  
- task: Npm@1
  inputs:
    command: 'install'
  displayName: npm install
  
- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run-script build --prod'
  displayName: 'npm build'
相关问题