-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.deploy
76 lines (76 loc) · 2.79 KB
/
Jenkinsfile.deploy
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
pipeline {
agent { label 'docker && linux' }
options {
timeout(time: 60, unit: 'MINUTES')
}
environment {
DOCKER_REGISTRY = 'docker.io'
DOCKER_CREDS = credentials('DockerHubCredential')
DOCKER_IMAGE = "${DOCKER_CREDS_USR}/smart-gate"
}
stages {
stage('Pre-Build Environment') {
steps {
echo "Name: ${env.BRANCH_NAME}"
echo "Change: ${env.CHANGE_ID}"
echo "Source branch: ${env.CHANGE_BRANCH}"
echo "Target branch: ${env.CHANGE_TARGET}"
echo "Branch is primary: ${env.BRANCH_IS_PRIMARY}"
echo "Tag name: ${env.TAG_NAME}"
echo "Tag date: ${env.TAG_DATE}"
echo "Commit: ${env.GIT_COMMIT}"
sh 'git status'
sh 'git fetch --tags'
sh 'git describe --tags'
}
}
stage('ARM & x86 Pipeline') {
matrix {
axes {
axis {
name 'PLATFORM'
values 'linux/arm/v7', 'linux/arm64/v8', 'linux/amd64'
}
}
stages {
stage('Build Image') {
steps {
echo "Building Image: ${DOCKER_IMAGE} for ${PLATFORM}"
sh'''
docker build --pull --force-rm --build-arg VERSION="${TAG_NAME}" --target prod --platform "${PLATFORM}" -t "${DOCKER_IMAGE}":$(echo "${PLATFORM}" | sed 's/\\//_/g') .
'''
}
}
}
}
}
stage('Publish Images') {
when {
tag "v*"
}
steps {
sh'''
echo $DOCKER_CREDS_PSW | docker login $DOCKER_REGISTRY --username $DOCKER_CREDS_USR --password-stdin
docker push --all-tags "${DOCKER_IMAGE}"
docker manifest create "${DOCKER_IMAGE}:${TAG_NAME}" \
"${DOCKER_IMAGE}":linux_arm_v7 \
"${DOCKER_IMAGE}":linux_arm64_v8 \
"${DOCKER_IMAGE}":linux_amd64
docker manifest inspect "${DOCKER_IMAGE}:${TAG_NAME}"
docker manifest push --purge "${DOCKER_IMAGE}:${TAG_NAME}"
docker logout
'''
}
}
}
post {
always {
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
}
}
}