reddit-reposter-bot/.gitlab-ci.yml
2020-11-07 12:11:47 +01:00

87 lines
2.5 KiB
YAML

image: docker:latest
services:
- docker:dind
stages:
- build
- test
- package
- release
variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# 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
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
paths:
- .m2/repository
# 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