mbohun
11/6/2014 - 5:49 AM

travis_after_success.sh

travis_after_success.sh

#!/bin/bash

# wget/download and source the unencrypted/common env variables you want to share among all ALA projects
wget -q https://raw.githubusercontent.com/AtlasOfLivingAustralia/travis-build-configuration/master/ala_common.sh
chmod +x ala_common.sh
source ./ala_common.sh

# build the grails project
grails clean && grails refresh-dependencies --non-interactive && grails prod war --non-interactive

# wget/download the generic/shared ~/.m2/settings.xml file
mkdir -p ~/.m2
wget  -q -O ~/.m2/settings.xml https://raw.githubusercontent.com/AtlasOfLivingAustralia/travis-build-configuration/master/travis_maven_settings.xml

# this env var can be unencrypted and set from one place for all projects; a project can customize/overwrite it if required
MAVEN_REPO=$ALA_MAVEN_REPO_ID

# this env var can be unencrypted and set from one place for all projects; a project can customize/overwrite it if required
GROUP_ID=$ALA_MAVEN_GROUP_ID

# did not manage to eliminate this part
RELEASE_OR_SNAPSHOT="snapshots"
grep '^\s*app\.version=' ./application.properties | grep -q "\-SNAPSHOT";
if [ "$?" = "1" ]; then
    RELEASE_OR_SNAPSHOT="releases";
fi;

# extract the app.version from application.properties
APP_VERSION=`grep "^\s*app\.version=" ./application.properties | sed -e "s/^\s*app\.version=//g" | tr -d "\r"`

# extract app.name (war name) from application.properties
APP_NAME=`grep "^\s*app\.name=" ./application.properties | sed -e "s/^\s*app\.name=//g" | tr -d "\r"`

# deploy
mvn -e deploy:deploy-file \
    -DartifactId=$APP_NAME \
    -DgroupId=$GROUP_ID \
    -Dpackaging=war \
    -Dversion=$APP_VERSION \
    -Dfile=target/$APP_NAME-$APP_VERSION.war \
    -DrepositoryId=$MAVEN_REPO \
    -Durl=$ALA_MAVEN_REPO_URL/$RELEASE_OR_SNAPSHOT
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <servers>

    <server>
      <!-- 
          We do not need a custom env var for <id> if we hardcode this to the default maven id: remote-repository.
          The maven deploy:deploy-file mojo when invoked WITHOUT -DrepositoryId is going to look for <id>remote-repository</id>
          in your ~/.m2/settings.xml file.
      -->
      <id>${ALA_MAVEN_REPO_ID}</id>

      <!-- these need to be encrypted individually for each repo, you can't source them form one single place :-( -->
      <username>${env.TRAVIS_DEPLOY_USERNAME}</username>
      <password>${env.TRAVIS_DEPLOY_PASSWORD}</password>
    </server>

  </servers>

</settings>
#!/bin/bash

# all ALA projects should use/source this value from this script
export ALA_MAVEN_REPO_URL="http://nexus.ala.org.au/content/repositories"

# we do not need this, if a custom <id> is NOT set (NOT used), and therefore NOT passed to maven deploy:deploy-file mojo in repositoryID
# maven will look for the "default" <id>remote-repository</id> in ~/.m2/settings.xml
export ALA_MAVEN_REPO_ID="ala-repo"