Travis-CI 尽管 Commit 被标记但跳过部署

Travis-CI skipping deployment although Commit is tagged

我对 Travis CI 还很陌生,但我使用他们的文档找到了自己的方法。但是部署到 GitHub 版本对我不起作用。 我的 .travis.yml 文件如下所示:

language: java

branches:
  only:
  - master

notifications:
  email: false

before_deploy:
  - export RELEASE_JAR_FILE=$(ls build/libs/*.jar)
  - echo "Deploying $RELEASE_JAR_FILE to GitHub"

deploy:
  provider: releases
  api_key:
    secure: [key]
  file_glob: true
  file: "${RELEASE_JAR_FILE}"
  skip_cleanup: true
  on:
    repo: [my-repo]
    tags: true
    all_branches: true

以下是我的承诺:

$ git add . && git commit -m "my message"
$ git tag 0.1234
$ git push origin --tags
$ git push origin master

之后,Travis 使用

创建构建并跳过部署
Skipping a deployment with the releases provider because this is not a tagged commit

当我在浏览器中打开我的 GitHub 存储库时,版本被正确标记,但 Travis 没有检测到它们被标记。

有人对此有解决方案吗?我怀疑 branches: only: master 部分对这种行为负责,尽管 Travis once 在没有 on: tags: true 标志的情况下将版本推到了 GitHub。之后,如果我遗漏了说我只能将标记的提交作为发布推送的标志,我就会出错。

您需要删除

branches:
    only:
    - master

https://github.com/travis-ci/travis-ci/issues/2498#issuecomment-48337712

我知道这很糟糕,但我不确定 Travis 是否可以按照您想要的方式进行配置。您可能要开票 - https://github.com/travis-ci/travis-ci/issues/new

更新:

branches.only 中的标签使用正则表达式:

branches:
    only:
    - master
    - /v\d+\.\d+[a-z]/

除了 所说的删除 branches 部分(这是必需的,因为不会调用标签构建)之外,您需要确保已推送标签 ( git push origin --tags) 所以标签存在于遥控器上。

deployment of release 只会发生在 标记的提交 上,不会发生在任何其他分支上,以避免多次发布相同的文件。已发布的标签将显示在 Travis CI 中的 Active Branches 下,其构建将触发发布,因此您应该看到如下输出:

Fetching: dpl-1.8.14.gem (100%)
Successfully installed dpl-1.8.14
Installing deploy dependencies
dpl.2
Preparing deploy
Logged in as X
Deploying to repo: FOO/BAR
Current tag is: FOOBAR-2015
dpl.3
Deploying application

构建成功后,您应该会在 Releases 选项卡下的 GitHub 上看到文件。


请查看:GitHub Releases Uploading 在 Travis CI 了解更多信息。

Travis CI 区分通过推送提交或拉取请求启动的构建和通过推送标签启动的构建。

TRAVIS_BRANCH: for push builds, or builds not triggered by a pull request, this is the name of the branch. for builds triggered by a pull request this is the name of the branch targeted by the pull request. for builds triggered by a tag, this is the same as the name of the tag (TRAVIS_TAG).

Source: https://docs.travis-ci.com/user/environment-variables/

因此,当推送带有标签的提交时,这将触发两个具有不同条件的构建。 如果您只过滤分支名称,则不会触发标签的构建!

您应该检查 if: 条件中的标签(here 是可能的谓词):

jobs:
  include:
  - # Build debug
    if: branch IN (develop, master)
    ...
  - # Build and deploy release on tags
    if: tag IS present
    ...

您可以查看我的示例 travis.yml 以获得 Android 个应用程序:https://travis-ci.com/G00fY2/android-ci-testproject/jobs/271171322/config