-
Notifications
You must be signed in to change notification settings - Fork 9
/
.gitlab-ci.yml
79 lines (74 loc) · 2.86 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# This file specifies GitLab CI/CD pipeline, see https://docs.gitlab.com/ee/ci/
#
# Git tags must be of the format X.Y.Z because they are used as maven project versions!
#
# Inspired by https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs/examples/release-assets-as-generic-package/
# defines stages in the pipeline
stages:
- build
- upload
- release
variables:
# variable read by Maven for JVM options, see https://maven.apache.org/configure.html#maven_opts-environment-variable
MAVEN_OPTS: " -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository "
# our own variable for repeated options
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version "
# URL for uploading files
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/chat/${CI_COMMIT_TAG}"
# the first job "build" belongs to the stage "build"
build:
# mark suitable for FI's shared runner
tags:
- shared-fi
# the stage for this job
stage: build
# name of Docker image in which the script commands are executed
image: maven:latest
# script is a list of linux shell commands
script:
# if the processed git commit is tagged, use the tag name as project version in pom.xml
- |
if [ -n "${CI_COMMIT_TAG}" ] ; then
echo "setting version ${CI_COMMIT_TAG}"
mvn versions:set -DnewVersion=${CI_COMMIT_TAG}
mvn versions:commit
fi
# run maven build
- 'mvn $MAVEN_CLI_OPTS clean install'
cache:
# caches maven repo between runs
paths:
- .m2/repository
artifacts:
# keeps produced files for the next job
paths:
- chat-server/target/chat_service.jar
- chat-client-java-lib/target/chat-client-java-lib.jar
# the second job named "upload" uploads produced JAR files into package registry
upload:
tags:
- shared-fi
stage: upload
image: curlimages/curl:latest
# the job runs only if the commit is tagged
rules:
- if: $CI_COMMIT_TAG
script:
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file chat-server/target/chat_service.jar ${PACKAGE_REGISTRY_URL}/chat_service.jar
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file chat-client-java-lib/target/chat-client-java-lib.jar ${PACKAGE_REGISTRY_URL}/chat-client-java-lib.jar
# the third job named "release" creates a release and links the produced JAR files as its assets
release:
tags:
- shared-fi
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
# the job runs only if the commit is tagged
rules:
- if: $CI_COMMIT_TAG
script:
- |
release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"chat_service.jar\",\"url\":\"${PACKAGE_REGISTRY_URL}/chat_service.jar\"}" \
--assets-link "{\"name\":\"chat-client-java-lib.jar\",\"url\":\"${PACKAGE_REGISTRY_URL}/chat-client-java-lib.jar\"}"