continuous-integration - 在 Travis yaml 中使用带有变量的 if 条件
问题描述
Travis 允许您在定义条件构建/阶段/作业的条件时使用内置的 Git 属性(例如,branch
、tag
、commit_message
等。更多信息在这里)。我有一个未包含在提供的列表中的属性:我想使用 Git 标签来确定一组阶段是否应该运行。因此,如果一个拉取请求上有一个 *release" 标签,那么它将运行额外的阶段,否则它们将被跳过。
我编写了一个脚本,如果包含或不包含发布标签,它将输出真或假,我希望用它来帮助决定一个阶段是否应该运行。这可能与.travis.yaml 有关吗?
本质上,我想知道具有以下设计的 .yaml 是否可以工作:
env:
- IS_RELEASE = false
before_install:
- git clone git@github.com:foo/bar.git foobar
- foobar/check_labels_for_release_tag.sh ${PR_NUMBER} ${GIT_TOKEN} # this script should set the IS_RELEASE above to either "true" or "false". It will use the Git API to check the PR to see if a label with the name "release" is on it or not.
jobs:
include:
- stage: Build
name: "Build"
script: foobar/build.sh
- stage: Test
name: "Test"
script: foobar/test.sh
# the following stage only runs if the IS_RELEASE variable is set to true
- stage: Release
name: "Release"
script: foobar/release.sh
if: IS_RELEASE = true
解决方案
推荐阅读
- r - 如何使用 3D 数组中的 image() 函数绘制 RGB 图像?
- python - Python旋转子数组内的元素
- python - 将背景颜色设置为 matplotlib 图表
- flutter - Flutter中的动画ListView项目位置变化
- java - 如何使用 Streams 创建复杂的字谜
- python - wtforms validate_on_submit 与空值行为
- reactjs - Material-UI 排版不在工具栏中居中
- knockout.js - Knockout js中的按钮没有点击if语句
- shell - 在大小边距内的所有目录中查找所有以 txt 和 out 结尾的文件
- android - 从 URI 获取 .mp3 原始资源的路径