17

I'm quite new to Travis CI, but I found my way through it using their docs. However deploying to GitHub releases doesn't work for me. My .travis.yml file looks like this:

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

Here's how I commit:

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

After that, Travis creates the build and skips deployment with

Skipping a deployment with the releases provider because this is not a tagged commit

When I open up my GitHub repository in my browser, the releases are tagged correctly, yet Travis doesn't detect them as tagged.

Does anybody have a solution for this? I suspected the branches: only: master part to be responsible for this behaviour, although Travis once pushed a release to GitHub without the on: tags: true flag. Afterwards I got errors if I left out the flag saying that I may only push tagged commits as release.

2
  • Could you provide link to repository on Github? Commented May 11, 2015 at 8:38
  • I didn't see a reason to add it as I basically trunkated my .travis.yml. Anyway, here's the link: github.com/minedev/MooseMachine
    – michaeln
    Commented May 11, 2015 at 10:36

3 Answers 3

18

You need to remove

branches:
    only:
    - master

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

I realize this is a bummer, but I am not sure that Travis can be configured in the way you desire. You may want to open a ticket - https://github.com/travis-ci/travis-ci/issues/new

UPDATE:

Use a regex for the tags in branches.only:

branches:
    only:
    - master
    - /v\d+\.\d+[a-z]/
3
  • Sorry, but I forgot to close this question. Thank you for searching it, but I already opened a ticked back then. To complete this, it can be solved by using a regex as branch name. Here's the issue I opened: github.com/travis-ci/travis-ci/issues/3897 , sorry
    – michaeln
    Commented Jul 8, 2015 at 20:31
  • 2
    Oh cool, I didn't know about the regexes. Thanks for the update =-D I updated the answer for others who may need it. Commented Jul 9, 2015 at 18:01
  • Be sure to check all occurrences of branch filters in your .travis.yml file. Usually, you can have a root branch filter as in the answer and also a filter within the deploy provider, e.g. deploy: // - provider: pypi // on: // only: // - master (// denotes newlines). Here, you would also need to add the version regex from the answer to it!
    – ComFreek
    Commented May 20, 2020 at 10:57
4

Travis CI differentiates between builds initiated by pushing a commit or pull request and builds initiated by pushing a tag.

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/

So when pushing a commit with a tag this will trigger two builds with different conditions. If you only filter your branch names, the build for the tag won't get triggered!

You should check for tags in the if: condition (here are the possible predicates):

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

You can check my example travis.yml for Android apps: https://travis-ci.com/G00fY2/android-ci-testproject/jobs/271171322/config

2
  • Question on this: will it still build on both the commit and the tag commit? Is there a way to only do the build for the tag if the commit was tagged? Having both running isn't too big a problem but it would be nice to be able to only run the tag stuff if the commit is tagged, rather than both.
    – Alex
    Commented Oct 8, 2020 at 17:17
  • 1
    From what I know pushing a commit with a tag will always trigger 2 builds. I am not aware that you can avoid that.
    – G00fY
    Commented Oct 8, 2020 at 20:07
2

Apart of what @Spain said about removing branches section (this is required, because the tag build won't be invoked), you need to make sure you've pushed the tags (git push origin --tags) so the tag exist on the remote.

The deployment of release will happen only for a tagged commit, not for any other branch to avoid publishing the same files multiple times. The released tag will show under Active Branches in Travis CI and its build will trigger the release, so you should see the output like:

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

After successful build, you should see the files on GitHub under Releases tab.


Please check: GitHub Releases Uploading at Travis CI for further info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.