I have been attempting to have Travis-CI automatically post its build product on GitHub Releases whenever a commit is pushed to [master].
我一直试图让travi - ci在提交到[master]时自动将其构建产品发布到GitHub发行版上。
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.
不幸的是,GitHub发行版需要一个标签来发布。作为一种解决方案,我尝试让Travis自动生成并对提交应用一个标记。然而,每次Travis更新存储库时,都会导致发布失败。
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:
我的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 "builds@travis-ci.com"
- 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://$TAGPERM@github.com/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:
示例Travis-CI日志:
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 "builds@travis-ci.com"
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://$TAGPERM@github.com/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 `'
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 `'
failed to deploy
19
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.
要部署的文件没有在.travis中正确列出。yml和gradle构建任务没有生成适当的.zip文件。
Here is the updated .travis.yml
:
以下是更新后的。travi .yml:
language: java
install: true
matrix:
include:
- jdk: oraclejdk8
script:
- gradle clean build
- gradle dist
before_deploy:
- git config --global user.email "builds@travis-ci.com"
- 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://$TAGPERM@github.com/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.
注意,这个构建的设置方式是,Travis每次提交都会运行两次,但只在第一次部署。这些可能值得进一步研究如何避免。
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.
另外,要注意在不正确地实现时,部署。on:标签= true,创建一个无限的Travis-CI构建循环。这样的结果不容易清理,在Travis中最明显的是由于无法删除构建历史。
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.
编辑:复制构建的解决方案在于Travis-CI处理标签推送的方式。@o11c在GitHub上为travi - ci第1532期找到了避免这种情况的诀窍。基本上,我们需要做的是用标记先行词排除分支。
In .travis.yml
this amounts to adding the following:
在.travis。这相当于增加了以下内容:
branches:
except:
- /^*-v[0-9]/
For posterity the final .travis.yml
amounts to:
为了子孙后代,特拉维斯。yml相当于:
language: java
install: true
matrix:
include:
- jdk: oraclejdk8
script:
- gradle clean build
- gradle dist
before_deploy:
- git config --global user.email "builds@travis-ci.com"
- 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://$TAGPERM@github.com/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]