【问题标题】:Travis conditional deployment: deploy script with regexp for branch skipped with error `branch not permitted`Travis 条件部署:使用正则表达式部署脚本以跳过错误“不允许分支”
【发布时间】:2019-11-28 16:13:50
【问题描述】:

我指定了多个部署脚本提供程序。预计会运行但被跳过的一个是:

- provider: script
  skip_cleanup: true
  script: curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --skip-publish
  verbose: true
  on:
    condition: "$TRAVIS_OS_NAME = linux"
    branches:
      only:
      - /^release\/.*$/
    go: 1.11.x
  • 最后三个部署仅在 master 分支上,因此可以跳过它们。

  • 在所有与 regexp 匹配的分支上的第一个部署:/^release/.*$/ 应该为此分支 release/2.1.5 运行。但是它也跳过了这个部署。

有人能指出为什么在这种情况下会跳过发布分支部署吗?我希望第一个部署在 linux 上运行并仅发布分支,例如:release/2.1.5。

特拉维斯构建:https://travis-ci.org/leopardslab/dunner/jobs/560593148

Travis 配置文件:https://github.com/leopardslab/dunner/blob/172a4c5792b0a8389556cc8ee4f690dc73fafb6e/.travis.yml

【问题讨论】:

    标签: regex deployment continuous-integration conditional-statements travis-ci


    【解决方案1】:

    要有条件地运行部署脚本,请仅在与正则表达式匹配的分支上说,例如发布分支^release\/.*$,使用条件字段并使用 && 连接多个条件。 branchbranches 字段不支持正则表达式。

    如果未指定 branchbranches 字段,则 travis 假定其位于 master 分支(或默认分支)上。所以一定要在 travis 配置中包含 all_branches: true 行。

    您可以使用 travis 环境变量 $TRAVIS_BRANCH 访问当前分支名称。

    deploy:
      - provider: script
        script: bash myscript.sh
        verbose: true
        on:
          all_branches: true
          condition: $TRAVIS_BRANCH =~ ^release\/.*$ && $TRAVIS_OS_NAME = linux
    

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 2018-03-20
      相关资源
      最近更新 更多