问题
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.
回答1:
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]/
回答2:
Travis CI differentiate 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/251675526/config
回答3:
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.
来源:https://stackoverflow.com/questions/30156581/travis-ci-skipping-deployment-although-commit-is-tagged