20
votes

I have been attempting to have Travis-CI automatically post its build product on GitHub Releases whenever a commit is pushed to [master].

Unfortunately, GitHub Releases requires a tag to release with. As a solution, I attempted to have Travis automatically generate and apply a tag to the commit. However, every time Travis updates the repository, it causes the release to fail.

As such, what am I doing wrong with my current setup and|or is there a way to do what I have described.

My travis.yml:

language: java
before_install: chmod +x gradlew
install: true
matrix:
  include:
  - jdk: oraclejdk8
script: ./gradlew build
before_deploy:
  - git config --global user.email "[email protected]"
  - git config --global user.name "Travis CI"
  - export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
  - git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
  - git push -q https://[email protected]/RlonRyan/JBasicX --tags
deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: [redacted]
  file:
    - "build/libs"
    - "build/classes/test/output"
  on:
    tags: false
    all_branches: true
env:
  global:
    secure: [redacted]

Sample Travis-CI log:

Using worker: worker-linux-e7a62211-1.bb.travis-ci.org:travis-linux-1

system_info

Build system information

Build language: java

Build image provisioning date and time

Sun Dec 7 05:49:51 UTC 2014

lsb_release -a

Distributor ID: Ubuntu

Description: Ubuntu 12.04 LTS

Release: 12.04

Codename: precise

Cookbooks Version

5736160 https://github.com/travis-ci/travis-cookbooks/tree/5736160

GCC version

gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Copyright (C) 2011 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

LLVM version

clang version 3.4 (tags/RELEASE_34/final)

Target: x86_64-unknown-linux-gnu

Thread model: posix

Pre-installed Ruby versions

ruby-1.9.3-p551

Pre-installed Node.js versions

v0.10.33

Pre-installed Go versions

go1.3.3

Redis version

redis-server 2.8.18

riak version

1.4.12

MongoDB version

MongoDB 2.4.12

CouchDB version

couchdb 1.6.1

Neo4j version

1.9.4

Cassandra version

2.0.9

RabbitMQ Version

3.4.2

ElasticSearch version

1.4.0

Installed Sphinx versions

2.0.10

2.1.9

2.2.4

Default Sphinx version

2.1.9

Installed Firefox version

firefox 31.0esr

PhantomJS version

1.9.8

ant -version

Apache Ant(TM) version 1.8.2 compiled on December 3 2011

mvn -version

Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T20:58:10+00:00)

Maven home: /usr/local/maven

Java version: 1.7.0_72, vendor: Oracle Corporation

Java home: /usr/lib/jvm/java-7-oracle/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "2.6.32-042stab090.5", arch: "amd64", family: "unix"

gradle -version

------------------------------------------------------------

Gradle 2.0

------------------------------------------------------------

Build time: 2014-07-01 07:45:34 UTC

Build number: none

Revision: b6ead6fa452dfdadec484059191eb641d817226c

Groovy: 2.3.3

Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013

JVM: 1.7.0_72 (Oracle Corporation 24.72-b04)

OS: Linux 2.6.32-042stab090.5 amd64

lein1 version

Using JLine for console I/O; install rlwrap for optimum experience.

Leiningen 1.7.1 on Java 1.7.0_72 Java HotSpot(TM) 64-Bit Server VM

lein2 version

Leiningen 2.5.0 on Java 1.7.0_72 Java HotSpot(TM) 64-Bit Server VM

lein version

Leiningen 2.5.0 on Java 1.7.0_72 Java HotSpot(TM) 64-Bit Server VM

git.checkout

0.26s$ git clone --depth=50 --branch=master git://github.com/RlonRyan/JBasicX.git RlonRyan/JBasicX

Cloning into 'RlonRyan/JBasicX'...

remote: Counting objects: 752, done.

remote: Compressing objects: 100% (348/348), done.

remote: Total 752 (delta 376), reused 688 (delta 335)

Receiving objects: 100% (752/752), 1.52 MiB | 0 bytes/s, done.

Resolving deltas: 100% (376/376), done.

Checking connectivity... done.

$ cd RlonRyan/JBasicX

$ git checkout -qf c89668db02576494a8678f8b8a782d87760f769a

Setting environment variables from .travis.yml

$ export TAGPERM=[secure]

$ jdk_switcher use oraclejdk8

Switching to Oracle JDK8 (java-8-oracle), JAVA_HOME will be set to /usr/lib/jvm/java-8-oracle

$ export TERM=dumb

$ java -version

java version "1.8.0_25"

Java(TM) SE Runtime Environment (build 1.8.0_25-b17)

Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

$ javac -version

javac 1.8.0_25
before_install

0.01s$ chmod +x gradlew
install

0.01s$ true

67.24s$ ./gradlew build

Downloading https://services.gradle.org/distributions/gradle-2.2.1-bin.zip

..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Unzipping /home/travis/.gradle/wrapper/dists/gradle-2.2.1-bin/88n1whbyjvxg3s40jzz5ur27/gradle-2.2.1-bin.zip to /home/travis/.gradle/wrapper/dists/gradle-2.2.1-bin/88n1whbyjvxg3s40jzz5ur27

Set executable permissions for: /home/travis/.gradle/wrapper/dists/gradle-2.2.1-bin/88n1whbyjvxg3s40jzz5ur27/gradle-2.2.1/bin/gradle

Download https://repo1.maven.org/maven2/junit/junit/4.11/junit-4.11.pom

Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom

Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-parent/1.3/hamcrest-parent-1.3.pom

Download https://repo1.maven.org/maven2/junit/junit/4.11/junit-4.11.jar

Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar

:compileJavaNote: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

:processResources

:classes

:jar

:assemble

:compileTestJavaNote: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

:processTestResources

:testClasses

:test

JTestsX.JTestsX > testCreateMenu STARTED

JTestsX.JTestsX > testCreateMenu PASSED

JTestsX.JTestsX > testCreateDrawing STARTED

JTestsX.JTestsX > testCreateDrawing PASSED

:check

:build

BUILD SUCCESSFUL

Total time: 1 mins 6.792 secs

The command "./gradlew build" exited with 0.
before_deploy.1

0.01s$ git config --global user.email "[email protected]"
before_deploy.2

0.01s$ git config --global user.name "Travis CI"
before_deploy.3

0.01s$ export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
before_deploy.4

0.01s$ git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
before_deploy.5

0.79s$ git push -q https://[email protected]/RlonRyan/JBasicX --tags
dpl.0

Fetching: dpl-1.7.9.gem (100%)

Successfully installed dpl-1.7.9

1 gem installed

dpl.1

Installing deploy dependencies

Fetching: addressable-2.3.6.gem (100%)

Successfully installed addressable-2.3.6

Fetching: multipart-post-2.0.0.gem (100%)

Successfully installed multipart-post-2.0.0

Fetching: faraday-0.9.1.gem (100%)

Successfully installed faraday-0.9.1

Fetching: sawyer-0.6.0.gem (100%)

Successfully installed sawyer-0.6.0

Fetching: octokit-3.7.0.gem (100%)

Successfully installed octokit-3.7.0

5 gems installed

Fetching: mime-types-2.4.3.gem (100%)

Successfully installed mime-types-2.4.3

1 gem installed

dpl.2

Preparing deploy

Logged in as RlonRyan

Deploying to repo: RlonRyan/JBasicX

remote: Counting objects: 23, done.

remote: Compressing objects: 100% (20/20), done.

remote: Total 23 (delta 16), reused 10 (delta 3)

Unpacking objects: 100% (23/23), done.

From git://github.com/RlonRyan/JBasicX

* [new tag] master-0.1.23-2015-01-29 -> master-0.1.23-2015-01-29

* [new tag] master-0.1.26-2015-01-29 -> master-0.1.26-2015-01-29

* [new tag] master-0.1.29-2015-01-29 -> master-0.1.29-2015-01-29

* [new tag] master-0.1.34 -> master-0.1.34

* [new tag] master-0.1.36 -> master-0.1.36

* [new tag] v0.1.0 -> v0.1.0

Current tag is: master-0.1.38

dpl.3

Deploying application

/home/travis/.rvm/gems/ruby-1.9.3-p551/gems/octokit-3.7.0/lib/octokit/client/releases.rb:86:in `initialize': Is a directory - build/libs (Errno::EISDIR)

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/octokit-3.7.0/lib/octokit/client/releases.rb:86:in `new'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/octokit-3.7.0/lib/octokit/client/releases.rb:86:in `upload_asset'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider/releases.rb:118:in `block in push_app'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider/releases.rb:102:in `each'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider/releases.rb:102:in `push_app'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider.rb:132:in `block in deploy'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/cli.rb:41:in `fold'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider.rb:132:in `deploy'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/cli.rb:32:in `run'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/cli.rb:7:in `run'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.7.9/bin/dpl:5:in `<top (required)>'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/bin/dpl:23:in `load'

from /home/travis/.rvm/gems/ruby-1.9.3-p551/bin/dpl:23:in `<main>'

failed to deploy
1

1 Answers

22
votes

There was nothing wrong with the concept, just the files being deployed.

The files that were meant to be deployed were not listed properly in the .travis.yml, and the gradle build task was not generating the proper .zip files.

Here is the updated .travis.yml:

language: java
install: true
matrix:
  include:
  - jdk: oraclejdk8
script:
  - gradle clean build
  - gradle dist
before_deploy:
  - git config --global user.email "[email protected]"
  - git config --global user.name "Travis CI"
  - export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
  - git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
  - git push -q https://[email protected]/RlonRyan/JBasicX --tags
  - ls -R
deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: [redacted]
  file:
    - "README.md"
    - "dist/JBasicX-Main-0.1.0.zip"
    - "dist/JBasicX-Test Output-0.1.0.zip"
  on:
    tags: false
    all_branches: true
env:
  global:
    secure: [redacted]

Note, the way this build is setup, Travis will run twice for every commit, but only deploy the 1st time. Such may be worth further investigation in how to avoid.

Also, beware when improperly implemented, that is deploy.on:tags = true, an infinite Travis-CI build loop is created. Such a result is not easy to clean up, and most noticeable in Travis due to the inability to delete build history.

Edit: The solution to the duplicated builds lies in the way Travis-CI treats tag pushes as commits. The trick to avoid this was found by @o11c on GitHub for Travis-CI issue #1532. Basically, what one needs to do is exclude branches with the tag antecedent.

In .travis.yml this amounts to adding the following:

branches:
  except:
    - /^*-v[0-9]/

For posterity the final .travis.yml amounts to:

language: java

install: true

matrix:
  include:
  - jdk: oraclejdk8

script:
  - gradle clean build
  - gradle dist

before_deploy:
  - git config --global user.email "[email protected]"
  - git config --global user.name "Travis CI"
  - export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
  - git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
  - git push -q https://[email protected]/RlonRyan/JBasicX --tags
  - ls -R

deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: [redacted]
  file:
    - "README.md"
    - "dist/JBasicX-Main-0.1.0.zip"
    - "dist/JBasicX-Test Output-0.1.0.zip"
  on:
    tags: false
    all_branches: true

branches:
  except:
    - /^*-v[0-9]/

notifications:
  email:
    on_success: change
    on_failure: change
  irc:
    channels:
      - "irc.esper.net#RlonRyan"
    on_success: always
    on_failure: always

env:
  global:
    secure: [redacted]