Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Travis-CI skipping deployment although Commit is tagged

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.

like image 876
michaeln Avatar asked May 10 '15 20:05

michaeln


2 Answers

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]/
like image 176
Spain Train Avatar answered Oct 14 '22 13:10

Spain Train


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

like image 34
G00fY Avatar answered Oct 14 '22 11:10

G00fY