Skip to content

spring-io/concourse-java-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Concourse Java Scripts

Useful bash scripts that help when building Java projects in Concourse.

Importing

Copy concourse-java.sh to your project or add it to the docker image you use for building. Add the following to your build script:

#!/bin/bash
set -e
source <folder>/concourse-java.sh
Note
This script requires a full bash environment. Some functions also require git.

Functions

Adds symlinks for Maven and/or Gradle caches. The current directory should contain maven and/or gradle cache folders as created by Concourse. Syslinks will be created in $HOME to .m2 and .gradle.

Setup caches in your task yaml:

task.yml
---
platform: linux
image_resource:
  type: docker-image
  ...
inputs:
- name: git-repo
outputs:
- name: built-artifact
caches:
- path: maven
- path: gralde
run:
  ...

Then call setup_symlinks early in your run script:

setup_symlinks
Tip
If ~/.m2 or ~/.gradle folders already exist, they will not be replaced

cleanup_maven_repo

Remove a folder from the local ~/.m2/repository folder. This command is often used to ensure that no accidental cache pollution has occurred.

Call with a single maven group identified. For example:

cleanup_maven_repo com.example.foo
cleanup_maven_repo com.example.bar

run_maven

Run ./mvnw from the current directory showing only a limiting subset of the logged output as long as the build succeeds. If the build fails, the last 3000 lines of output are shown.

For example, given the following call:

run_maven clean install

A successful build would show output looking something like this:

./mvnw clean install
[INFO] ------------------------------------------------------------------------
[INFO] Building example-project 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ example-project ---
[INFO] --- maven-checkstyle-plugin:2.17:check (checkstyle-validation) @ example-project ---
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ example-project ---
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ example-project ---
[INFO] --- build-helper-maven-plugin:1.10:add-test-source (add-test-source) @ example-project ---
[INFO] --- build-helper-maven-plugin:1.10:add-test-resource (add-test-resources) @ example-project ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ example-project ---
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ example-project ---
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ example-project ---

get_revision_from_pom

Gets the <revision> property from a pom.xml in the current directory. For example, given the following pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.example</groupId>
	<artifactId>example-project</artifactId>
	<version>${revision}</version>
	<properties>
		<revision>1.0.0-SNAPSHOT</revision>
		<java.version>1.8</java.version>
	</properties>
</project>

The following call would set version to 1.0.0-SNAPSHOT:

version=$( get_revision_from_pom )
Note
This command relies on xmllint being installed
Tip
For details of how you can use <revision> in your builds see Maven CI Friendly Versions

set_revision_to_pom

Sets the <version> property to a pom.xml in the current directory.

For example, given the following pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.example</groupId>
	<artifactId>example-project</artifactId>
	<version>${revision}</version>
	<properties>
		<revision>1.0.0-SNAPSHOT</revision>
		<java.version>1.8</java.version>
	</properties>
</project>

The following call would set version to 2.0.0:

set_revision_to_pom "2.0.0"
Tip
For details of how you can use <revision> in your builds see Maven CI Friendly Versions

bump_version_number

Updates a version number by bumping the milestone (M), release candidate (RC) or patch number.

For example, if version is 1.2.3 the result in next will be 1.2.4:

next=$( bump_version_number $version)

The following formats are supported:

Input Output

1.2.3

1.2.4

1.2.3-SNAPSHOT

1.2.4-SNAPSHOT

1.2.3.BUILD-SNAPSHOT

1.2.4.BUILD-SNAPSHOT

1.2.3.RELEASE

1.2.4.RELEASE

1.2.3-M1

1.2.3-M2

1.2.3.M1

1.2.3.M2

1.2.3-RC1

1.2.3-RC2

1.2.3.RC1

1.2.3.RC2

strip_snapshot_suffix

Remove any -SNAPSHOT or .BUILD-SNAPSHOT suffix from the provided version number.

For example, the following would both set version to "1.2.3":

version=$( strip_snapshot_suffix "1.2.3-SNAPSHOT" )
version=$( strip_snapshot_suffix "1.2.3.BUILD-SNAPSHOT" )

get_next_release

Get the release version based on a given snapshot version.

The following call will set next to 1.0.0.

next=$( get_next_milestone_release "1.0.0.BUILD-SNAPSHOT" )

You can also configure a release suffix; the following call will set next to 1.0.0.RELEASE.

next=$( get_next_milestone_release "1.0.0.BUILD-SNAPSHOT" "RELEASE" )
Tip
Version numbers in the form 1.0.0-SNAPSHOT and 1.0.0.BUILD-SNAPSHOT are both supported

get_next_milestone_release / get_next_rc_release

Get the next milestone or release candidate version based on a given version and existing git tags. These methods allow preview releases to be published, without needing to directly store the release number.

For example, given a repository with the following tags:

$ git tag --list
v1.0.0.M1
v1.0.0.M2
v1.0.0.M3

The following call will set next to 1.0.0.M4.

next=$( get_next_milestone_release "1.0.0.BUILD-SNAPSHOT")
Tip
Version numbers in the form 1.0.0-SNAPSHOT and 1.0.0.BUILD-SNAPSHOT are both supported

Contributing

See CONTRIBUTING.adoc for details of how to contribute.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages