-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile_Original
219 lines (204 loc) · 7.11 KB
/
Jenkinsfile_Original
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
properties([
parameters ([
booleanParam(name: 'CLEAN_WORKSPACE', defaultValue: true, description: 'Clean the workspace at the end of the run'),
string(name: 'DOCKER_REGISTRY_DOWNLOAD_URL', defaultValue: 'nexus-docker-private-group.ossim.io', description: 'Repository of docker images')
]),
pipelineTriggers([
[$class: "GitHubPushTrigger"]
]),
[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/ossimlabs/omar-geoscript'],
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '', numToKeepStr: '20')),
disableConcurrentBuilds()
])
podTemplate(
containers: [
containerTemplate(
name: 'docker',
image: 'docker:19.03.11',
ttyEnabled: true,
command: 'cat',
privileged: true
),
containerTemplate(
image: "${DOCKER_REGISTRY_DOWNLOAD_URL}/omar-builder:jdk11",
name: 'builder',
command: 'cat',
ttyEnabled: true
),
containerTemplate(
image: "${DOCKER_REGISTRY_DOWNLOAD_URL}/alpine/helm:3.2.3",
name: 'helm',
command: 'cat',
ttyEnabled: true
),
containerTemplate(
image: "${DOCKER_REGISTRY_DOWNLOAD_URL}/kubectl-aws-helm:latest",
name: 'kubectl-aws-helm',
command: 'cat',
ttyEnabled: true,
alwaysPullImage: true
),
],
volumes: [
hostPathVolume(
hostPath: '/var/run/docker.sock',
mountPath: '/var/run/docker.sock'
),
]
)
{
node(POD_LABEL){
stage("Checkout branch")
{
scmVars = checkout(scm)
GIT_BRANCH_NAME = scmVars.GIT_BRANCH
BRANCH_NAME = """${sh(returnStdout: true, script: "echo ${GIT_BRANCH_NAME} | awk -F'/' '{print \$2}'").trim()}"""
VERSION = """${sh(returnStdout: true, script: "cat chart/Chart.yaml | grep version: | awk -F'version:' '{print \$2}'").trim()}"""
GIT_TAG_NAME = "omar-geoscript" + "-" + VERSION
ARTIFACT_NAME = "ArtifactName"
script {
if (BRANCH_NAME != 'master') {
buildName "${VERSION} - ${BRANCH_NAME}-SNAPSHOT"
} else {
buildName "${VERSION} - ${BRANCH_NAME}"
}
}
}
stage("Load Variables")
{
withCredentials([string(credentialsId: 'o2-artifact-project', variable: 'o2ArtifactProject')]) {
step ([$class: "CopyArtifact",
projectName: o2ArtifactProject,
filter: "common-variables.groovy",
flatten: true])
}
load "common-variables.groovy"
switch (BRANCH_NAME) {
case "master":
TAG_NAME = VERSION
break
case "dev":
TAG_NAME = "latest"
break
default:
TAG_NAME = BRANCH_NAME
break
}
DOCKER_IMAGE_PATH = "${DOCKER_REGISTRY_PRIVATE_UPLOAD_URL}/omar-geoscript"
}
stage('SonarQube Analysis') {
nodejs(nodeJSInstallationName: "${NODEJS_VERSION}") {
def scannerHome = tool "${SONARQUBE_SCANNER_VERSION}"
withSonarQubeEnv('sonarqube'){
sh """
${scannerHome}/bin/sonar-scanner \
-Dsonar.projectKey=omar-geoscript
"""
}
}
}
stage('Build') {
container('builder') {
sh """
./gradlew assemble \
-PossimMavenProxy=${MAVEN_DOWNLOAD_URL}
./gradlew copyJarToDockerDir \
-PossimMavenProxy=${MAVEN_DOWNLOAD_URL}
"""
archiveArtifacts "plugins/*/build/libs/*.jar"
archiveArtifacts "apps/*/build/libs/*.jar"
}
}
stage ("Publish Nexus"){
container('builder'){
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'nexusCredentials',
usernameVariable: 'MAVEN_REPO_USERNAME',
passwordVariable: 'MAVEN_REPO_PASSWORD']])
{
sh """
./gradlew publish \
-PossimMavenProxy=${MAVEN_DOWNLOAD_URL}
"""
}
}
}
stage('Docker build') {
container('docker') {
withDockerRegistry(credentialsId: 'dockerCredentials', url: "https://${DOCKER_REGISTRY_DOWNLOAD_URL}") { //TODO
if (BRANCH_NAME == 'master'){
sh """
docker build --network=host -t "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:"${VERSION}" ./docker
"""
}
else {
sh """
docker build --network=host -t "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:"${VERSION}".a ./docker
"""
}
}
}
}
stage('Docker push'){
container('docker') {
withDockerRegistry(credentialsId: 'dockerCredentials', url: "https://${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}") {
if (BRANCH_NAME == 'master'){
sh """
docker push "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:"${VERSION}"
"""
}
else if (BRANCH_NAME == 'dev') {
sh """
docker tag "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:"${VERSION}".a "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:dev
docker push "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:"${VERSION}".a
docker push "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:dev
"""
}
else {
sh """
docker push "${DOCKER_REGISTRY_PUBLIC_UPLOAD_URL}"/omar-geoscript:"${VERSION}".a
"""
}
}
}
}
stage('Package chart'){
container('helm') {
sh """
mkdir packaged-chart
helm package -d packaged-chart chart
"""
}
}
stage('Upload chart'){
container('builder') {
withCredentials([usernameColonPassword(credentialsId: 'helmCredentials', variable: 'HELM_CREDENTIALS')]) {
sh "curl -u ${HELM_CREDENTIALS} ${HELM_UPLOAD_URL} --upload-file packaged-chart/*.tgz -v"
}
}
}
stage('New Deploy'){
container('kubectl-aws-helm') {
withAWS(
credentials: 'Jenkins-AWS-IAM',
region: 'us-east-1'){
if (BRANCH_NAME == 'master'){
//insert future instructions here
}
else if (BRANCH_NAME == 'dev') {
sh "aws eks --region us-east-1 update-kubeconfig --name gsp-dev-v2 --alias dev"
sh "kubectl config set-context dev --namespace=omar-dev"
sh "kubectl rollout restart deployment/omar-geoscript"
}
else {
sh "echo Not deploying ${BRANCH_NAME} branch"
}
}
}
}
stage("Clean Workspace"){
if ("${CLEAN_WORKSPACE}" == "true")
step([$class: 'WsCleanup'])
}
}
}