Added some more stages such as release and refactored to use the gitlab registry

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2020-11-07 12:10:09 +01:00
parent 34e91dcc0d
commit 3b7fff8a17

View File

@ -1,13 +1,12 @@
# This file is a template, and might need editing before it works on your project.
# Build JAVA applications using Apache Maven (http://maven.apache.org)
# For docker image tags see https://hub.docker.com/_/maven/
#
# For general lifecycle information see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
image: docker:latest
services:
- docker:dind
# This template will build and test your projects
# * Caches downloaded dependencies and plugins between invocation.
# * Verify but don't deploy merge requests.
# * Deploy built artifacts from master branch only.
stages:
- build
- test
- package
- release
variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
@ -17,9 +16,12 @@ variables:
# when running from the command line.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
# Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
CONTAINER_BRANCH_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
# This template uses jdk8 for verifying and deploying images
image: maven:3.6.3-jdk-14
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
@ -29,12 +31,54 @@ cache:
# Compile
compile: &compile
# This template uses jdk8 for verifying and deploying images
image: maven:3.6.3-jdk-14
stage: build
script:
- 'mvn $MAVEN_CLI_OPTS compile'
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths: .m2/repository
# Run tests
test: &test
image: maven:3.6.3-jdk-14
stage: test
script:
- 'mvn $MAVEN_CLI_OPTS test'
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths: .m2/repository
package:
image: maven:3.6.3-jdk-14
stage: package
script: 'mvn $MAVEN_CLI_OPTS assemble:single'
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths: .m2/repository
artifacts:
paths:
- target/*.jar
release:
stage: release
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build . -t $CONTAINER_BRANCH_IMAGE
- docker push $CONTAINER_BRANCH_IMAGE
except:
- master
release-master:
stage: release
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build . -t $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master