This repository has been archived by the owner on Mar 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
127 lines (113 loc) · 3.78 KB
/
Jenkinsfile
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
pipeline {
agent {
kubernetes {
// Change the name of jenkins-maven label to be able to use yaml configuration snippet
label "maven-dind"
// Inherit from Jx Maven pod template
inheritFrom "maven"
// Add pod configuration to Jenkins builder pod template
yamlFile "maven-dind.yaml"
}
}
environment {
ORG = "activiti"
APP_NAME = "activiti-cloud-notifications-graphql"
VERSION = jx_release_version()
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
GITHUB_CHARTS_REPO = "https://github.com/${ORG}/activiti-cloud-helm-charts.git"
GITHUB_HELM_REPO_URL = "https://${ORG}.github.io/activiti-cloud-helm-charts/"
RELEASE_BRANCH = "master"
}
stages {
stage("CI Build and push snapshot") {
when {
branch "PR-*"
}
environment {
PROJECT_VERSION = maven_project_version()
VERSION = "$PROJECT_VERSION".replaceAll("SNAPSHOT","$BRANCH_NAME-$BUILD_NUMBER-SNAPSHOT")
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
}
steps {
container("maven") {
sh "mvn versions:set -DnewVersion=$VERSION"
sh "mvn install -DskipITs=false"
sh "export VERSION=$VERSION && skaffold build -f skaffold.yaml"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$VERSION"
// Let's build chart to check for any errors
dir("./charts/$APP_NAME") {
sh "make preview"
}
sh "mvn deploy -DskipTests"
}
}
}
stage("Build Release") {
when {
branch "${RELEASE_BRANCH}"
}
steps {
container("maven") {
// ensure we're not on a detached head
sh "git checkout ${RELEASE_BRANCH}"
sh "git config --global credential.helper store"
sh "jx step git credentials"
// so we can retrieve the version in later steps
sh "echo $VERSION > VERSION"
sh "mvn versions:set -DnewVersion=$VERSION"
sh "mvn clean install -DskipIT=false"
dir ("./charts/$APP_NAME") {
sh "make build tag"
}
sh "export VERSION=$VERSION && skaffold build -f skaffold.yaml"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$VERSION"
sh "mvn deploy -DskipTests"
}
}
}
stage("Promote to Environments") {
when {
branch "${RELEASE_BRANCH}"
}
steps {
container("maven") {
dir ("./charts/$APP_NAME") {
sh "jx step changelog --generate-yaml=false --version v$VERSION"
// publish to github
retry(5) {
sh "make github"
}
sh 'sleep 8'
// Update versions
retry(2) {
sh "make updatebot/push-version"
}
}
}
}
}
}
post {
failure {
slackSend(
channel: "#activiti-community-builds",
color: "danger",
message: "$BUILD_URL"
)
}
always {
cleanWs()
}
}
}
def jx_release_version() {
container('maven') {
return sh( script: "echo \$(jx-release-version)", returnStdout: true).trim()
}
}
def maven_project_version() {
container('maven') {
return sh( script: "echo \$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -f pom.xml)", returnStdout: true).trim()
}
}