Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a Maven version to Github using Travis CI

I successfully managed to deploy a JAR from a maven project to Github using tags. However, current configuration assumes that the file name of the JAR always stays the same, which it doesn't. When I do a new release this will change accordingly so deployment will fail.

Is there a way I can use kind of wildcards in the YAML file? From what I found here on Stackoverflow and on the web, wildcards are not supported in YAML. I couldn't find another hack for doing this without manipulating the .travis.yml file itself, which I would like to avoid.

The version string is available in pom.xml.

Current .travis.yml:

language: java
jdk:
- openjdk7

deploy:
  provider: releases
  api_key:
    secure: asfdsdflkjsdflkj...
  file: target/helloci-1.0-SNAPSHOT.jar
  on:
    repo: ktk/helloci
    all_branches: true
    tags: true

I could surely script that somehow but then Travis CI would change its own configuration file and I'm not sure if this a) will work and b) is a good idea.

Repo I'm playing with: https://github.com/ktk/helloci

like image 215
Adrian Gschwend Avatar asked Sep 18 '14 15:09

Adrian Gschwend


3 Answers

A work around is to have maven generate the file using a fixed name, this can be done with

<build>
    <finalName>helloci</finalName>
</build>

However you probably want to keep the name as per maven conventions if you're not building on travis-ci. You can achieve this by adding the following to your pom:

<properties>
    <finalName>${project.artifactId}-${project.version}</finalName>
</properties>
<build>
    <finalName>${finalName}</finalName>

And passing -DfinalName=helloci when executing maven by adding the following 2 lines to your .travis.yml file:

before_install: mvn install -DskipTests=true -DfinalName=helloci
install: mvn test

You might also want to add the tag name to the name of the generated file. This can be achieved with:

before_install: mvn install -DskipTests=true -DfinalName=helloci-$TRAVIS_TAG
deploy:
  file: target/helloci-$TRAVIS_TAG.jar
like image 57
Reto Gmür Avatar answered Nov 09 '22 15:11

Reto Gmür


Wildcards are supported now, I run this setup:

before_deploy:
  - "mvn -DskipTests package"
  - export FOO=$(ls target/foo-version-*.jar)

deploy:
  provider: releases
  api_key:
    secure: yep
  file: "${FOO}"
like image 24
hennr Avatar answered Nov 09 '22 16:11

hennr


Sorry, wildcard patterns don't work at the moment, but we'll have a look into making that possible on Travis CI.

like image 29
roidrage Avatar answered Nov 09 '22 16:11

roidrage