-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfileRelease
83 lines (81 loc) · 2.73 KB
/
JenkinsfileRelease
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
80
81
82
83
pipeline {
agent none
environment {
DOCKER_REGISTRY = credentials('github_docker_registry')
}
stages {
stage('Build and release') {
agent {
docker {
image 'maven:3.8.3-openjdk-17'
args '-u 1000:999 -v /home/jenkins/.m2:/var/maven/.m2 -v /home/jenkins/.gnupg:/.gnupg -v /var/run/docker.sock:/var/run/docker.sock:ro -e MAVEN_CONFIG=/var/maven/.m2 -e MAVEN_OPTS=-Duser.home=/var/maven'
}
}
environment {
GITHUB = credentials('Github-Username-Pw')
GITHUB_RELEASE_TOKEN = credentials('github_registry_release')
GIT_ASKPASS='./.git-askpass'
}
stages {
stage ('Ensure dev branch') {
when {
expression {
return env.BRANCH_NAME != 'dev';
}
}
steps {
error("Releasing is only possible from dev branch")
}
}
stage ('Set Git Information') {
steps {
sh 'echo \'echo \$GITHUB_PSW\' > ./.git-askpass'
sh 'chmod +x ./.git-askpass'
sh 'git config url."https://[email protected]/".insteadOf "https://github.com/"'
sh 'git config url."https://[email protected]/".insteadOf "ssh://[email protected]/"'
sh 'git config url."https://[email protected]/".insteadOf "[email protected]:"'
sh 'git config user.email "[email protected]"'
sh 'git config user.name "Jenkins"'
}
}
stage('Create release branch') {
steps {
sh 'mvn -B -Prelease gitflow:release-start'
}
}
stage('Build and push release') {
steps {
sh 'mvn -B -Prelease "-Ddocker.publish.usr=\${DOCKER_REGISTRY_USR}" "-Ddocker.publish.psw=\${DOCKER_REGISTRY_PSW}" -Dspring-boot.build-image.publish=true clean spring-boot:build-image'
}
}
stage('Update readme') {
steps {
sh 'git add README.md RELEASE_NOTES.md'
sh 'git commit -m "Update README and RELEASE_NOTES"'
}
}
stage('Merge release branch') {
steps {
sh "mvn -B gitflow:release-finish"
}
}
stage('Create GitHub release') {
steps {
sh 'git checkout master'
sh "mvn -B github-release:github-release -Dgithub.release-token=${GITHUB_RELEASE_TOKEN}"
}
}
}
}
stage('Deploy to production') {
agent any
environment {
VERSION = 'latest'
}
steps {
sh 'docker login -u ${DOCKER_REGISTRY_USR} -p ${DOCKER_REGISTRY_PSW} ghcr.io'
sh 'docker stack deploy --compose-file swarm-stack/production.yml --prune --with-registry-auth gh-prom-exporter'
}
}
}
}