首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有条件地向Azure管道中的发布步骤添加--dry-run

有条件地向Azure管道中的发布步骤添加--dry-run
EN

Stack Overflow用户
提问于 2021-02-12 03:28:50
回答 1查看 171关注 0票数 1

我们在Azure管道中有这个步骤。如果分支为main,则运行npm run publish-shell-ui,否则跳过该步骤。我想修改此步骤,以便在分支不是main的情况下添加--dry-run选项。

代码语言:javascript
复制
  - task: Npm@1
    displayName: "Publish"
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
    inputs:
      command: 'custom'
      customCommand: 'run publish-shell-ui'
      workingDir: '$(BuildRoot)'

我知道我可以通过添加第二个“预演发布”任务来解决这个问题,这个任务只在分支不是main时运行,但我在问是否可以创建一个可以处理这两种情况的任务,因为我怀疑这样的解决方案会更容易阅读。

代码语言:javascript
复制
  - task: Npm@1
    displayName: "Dry-Run Publish"
    condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main'))
    inputs:
      command: 'custom'
      customCommand: 'run publish-shell-ui --dry-run'
      workingDir: '$(BuildRoot)'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-13 00:41:02

我过去使用的是变量来存储值,这些值根据传递到YAML管道/模板的参数进行更改。

我相信这样的东西会实现你正在寻找的东西:

代码语言:javascript
复制
- script: |
   branch='$(Build.SourceBranch)'
   if [[ $branch == *"/main"* ]]
   then
      echo '##vso[task.setvariable variable=PublishCommand]run publish-shell-ui
   else
      echo '##vso[task.setvariable variable=PublishCommand]run publish-shell-ui --dry-run
   fi
  displayName: "Set Publish Command" 
  condition: ne(variables['Build.SourceBranch'], 'refs/heads/main')      
- task: Npm@1
  displayName: "Publish"
  condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main'))
  inputs:
     command: 'custom'
     customCommand: $(PublishCommand)
     workingDir: '$(BuildRoot)'
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66161525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档