-
Notifications
You must be signed in to change notification settings - Fork 40
/
Jenkinsfile.postmerge
119 lines (113 loc) · 4.51 KB
/
Jenkinsfile.postmerge
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
#! /usr/bin/env groovy
pipeline {
agent { label 'docker' }
environment {
DOCKERHUB_RW_USERNAME = 'svcmaterials'
GIT_SUBJECT = sh (
script: 'git show --format=oneline --no-patch',
returnStdout: true
).trim()
GIT_AUTHOR = sh (
script: 'git show -s --pretty=%an',
returnStdout: true
).trim()
SERVICE_NAME = 'canvas-rce-api'
STARLORD_IMAGE_TAG = 'starlord.inscloudgate.net/jenkins/canvas-rce-api'
CONFIG_ARG = '--config .canvas-rce-api.json'
}
options {
ansiColor("xterm")
timeout(time: 50, unit: 'MINUTES')
disableConcurrentBuilds()
}
stages {
stage('Build and Push Docker Images') {
parallel {
stage('Cloudgate') {
steps {
withCredentials([sshUserPrivateKey(credentialsId: '44aa91d6-ab24-498a-b2b4-911bcb17cc35', keyFileVariable: 'SSH_KEY_PATH', usernameVariable: 'SSH_USERNAME')]) {
sh '''
GIT_SSH_COMMAND='ssh -i "$SSH_KEY_PATH" -l "$SSH_USERNAME"' git clone --depth 1 ssh://${GERRIT_HOST}:29418/RichContentService
'''
}
dir('RichContentService') {
withCredentials([sshUserPrivateKey(credentialsId: '44aa91d6-ab24-498a-b2b4-911bcb17cc35', keyFileVariable: 'SSH_KEY_PATH', usernameVariable: 'SSH_USERNAME')]) {
sh '''
GIT_SSH_COMMAND='ssh -i "$SSH_KEY_PATH" -l "$SSH_USERNAME"' git submodule update --init
'''
}
cloudgateBuild(cgEnvironment: "build", cgVersion: "12.3", tfVersion: "0.13")
}
}
post {
failure {
slackSend channel: "#rcx-eng", color: 'danger', message: "${env.SERVICE_NAME}: CG build failed (<${env.BUILD_URL}|Open>). Changes: \n - ${env.GIT_SUBJECT} [${env.GIT_AUTHOR}]"
}
success {
slackSend channel: "#rcx-eng", color: 'good', message: "${env.SERVICE_NAME}: CG build successful (<${env.BUILD_URL}|Open>). Changes: \n - ${env.GIT_SUBJECT} [${env.GIT_AUTHOR}]"
}
}
}
stage(':latest') {
steps {
script {
withMultiPlatformBuilder {
withCredentials([string(credentialsId: 'dockerhub-materials-rw', variable: 'DOCKERHUB_RW_PASSWORD')]) {
sh 'echo $DOCKERHUB_RW_PASSWORD | docker login --username $DOCKERHUB_RW_USERNAME --password-stdin'
}
sh """
docker buildx build \
--builder multi-platform-builder \
--pull \
--push \
--platform=linux/amd64,linux/arm64 \
--tag "${STARLORD_IMAGE_TAG}:latest" \
--tag "${STARLORD_IMAGE_TAG}:master" \
--tag instructure/canvas-rce-api:latest \
.
"""
}
}
}
}
stage('New Release') {
// When the git tag starts with the letter "v" followed by one or more digits, we know this commit is a new release
when { tag pattern: "v\\d+", comparator: "REGEXP"}
// We use an environment variable instead of a Groovy variable here because combining env var interpolation
// with Groovy interpolation in a multiline Jenkins pipeline string is fraught with problems.
environment {
VERSION = sh (
script: "docker-compose run --rm web node -p \"require('./package.json').version\"",
returnStdout: true
).trim()
}
steps {
script {
withMultiPlatformBuilder {
withCredentials([string(credentialsId: 'dockerhub-materials-rw', variable: 'DOCKERHUB_RW_PASSWORD')]) {
sh 'echo $DOCKERHUB_RW_PASSWORD | docker login --username $DOCKERHUB_RW_USERNAME --password-stdin'
}
sh """
docker buildx build \
--builder another-multi-platform-builder \
--pull \
--push \
--platform=linux/amd64,linux/arm64 \
--tag "${STARLORD_IMAGE_TAG}:${VERSION}" \
--tag "instructure/canvas-rce-api:release-${VERSION}" \
.
"""
}
}
}
}
}
}
}
post {
cleanup {
sh 'docker $CONFIG_ARG logout "https://index.docker.io/v1/"'
sh 'docker logout "https://index.docker.io/v1/"'
}
}
}