azure - 如何使用 yml 文件为 azure 管道中的不同分支设置不同的参数
问题描述
这是我正在尝试的 YML 代码。我有一个要求,在每个分支中都需要设置不同的参数。
例如,声纳分析只应在自动集成和部署时在开发分支中运行。我想知道如何根据分支将默认属性配置为 true。
parameters:
- name: sonar_analysis
displayName: Sonarqube Analysis
type: boolean
default: true
- name: docker_build_push
displayName: Docker Build and Push
type: boolean
default: false
- name: sonar_publish
displayName: Sonarqube Publish
type: boolean
default: false
- name: owasp_dep_check
displayName: OWASP Dependency Check
type: boolean
default: false
- name: angular_build
displayName: Angular Build
type: boolean
default: false
- name: angular_build_gzip
displayName: Angular Build GZIP
type: boolean
default: false
# specific path build
trigger:
batch: true
branches:
include:
- master
- development
# YAML file in the main branch
schedules:
- cron: "0 0 * * *"
displayName: Daily midnight build
branches:
include:
- main
pool:
vmImage: ubuntu-latest
variables:
docker_ng_tag: 0.0.1
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.16.0'
- ${{ if eq(parameters.angular_build, true) }}:
- script: |
npm install -g @angular/cli@11.2.2
npm install
npm link @angular/cli
ng build --prod --aot --base-href /app/tms/ --deploy-url /app/tms/
displayName: 'npm install and build'
- ${{ if eq(parameters.angular_build_gzip, true) }}:
- script: |
npm i gzipper@4.4.0 -g
gzipper compress ./dist
displayName: 'GZIP'
解决方案
您可以像这样定义变量:
variables:
isDevelopment: $[eq(variables['Build.SourceBranch'], 'refs/heads/development')]
stages:
- stage: A
jobs:
- job: A1
steps:
- script: echo Hello Stage A!
- stage: B
condition: and(succeeded(), eq(variables.isDevelopment, 'true'))
jobs:
- job: B1
steps:
- script: echo Hello Stage B!
- script: echo $(isDevelopment)
您也可以在步骤级别上使用条件。
我们知道在 cron 中您使用main
分支和在 ci 触发器master
中。我很确定你两者都没有。
推荐阅读
- reactjs - React Quill - 如何显示两个文本版本之间的差异?
- makefile - `make` 不会自动链接本地安装的库(CS50x 的 cs50.h)
- python - 在 pandas 中获取每个组的分布的 df
- javascript - Leaflet - 即使在删除事件侦听器后,标记也不会停止移动
- ruby-on-rails - 渲染集合 [where(store: current_user).each do] ?如何从渲染加载特定数据
- c++ - 获取多处理器的 Windows CPU 利用率的正确方法
- python-3.8 - 在 while 循环中写入 plt.show() 行后,如何成功输入输入?
- r - 在R中的数据框中随机交换两个不同列中的一定数量的条目
- json - VBA解析JSON空数据
- python - 升级自制软件 ocrmypdf 致命 Python 错误后:config_get_locale_encoding: failed to get the locale encoding: nl_langinfo