forked from darey-io/tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
145 lines (124 loc) · 4.1 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pipeline {
agent any
environment
{
PROJECT = 'zooto-tooling-prod'
ECRURL = '059636857273.dkr.ecr.eu-central-1.amazonaws.com'
DEPLOY_TO = 'development'
}
stages {
stage("Initial cleanup") {
steps {
dir("${WORKSPACE}") {
deleteDir()
}
}
}
stage('Checkout')
{
steps {
checkout([
$class: 'GitSCM',
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
// branches: [[name: '$branch']],
userRemoteConfigs: [[url: "https://github.com/darey-io/tooling.git ",credentialsId:'GITHUB_CREDENTIALS']]
])
}
}
// stage('Checkout Helm chart')
// {
// steps {
// checkout([
// $class: 'GitSCM',
// doGenerateSubmoduleConfigurations: false,
// extensions: [[$class: 'RelativeTargetDirectory',
// relativeTargetDir: 'helm']],
// submoduleCfg: [],
// branches: [[name: 'master']],
// userRemoteConfigs: [[url: "https://gitlab.com/propitix/kubernetes/helm.git",credentialsId:'GIT_CREDENTIALS']]
// ])
// }
// }
stage('Build preparations')
{
steps
{
script
{
// calculate GIT lastest commit short-hash
gitCommitHash = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
shortCommitHash = gitCommitHash.take(7)
// calculate a sample version tag
VERSION = shortCommitHash
// set the build display name
currentBuild.displayName = "#${BUILD_ID}-${VERSION}"
IMAGE = "$PROJECT:$VERSION"
}
}
}
stage('Build For Dev Environment') {
when {
expression { BRANCH_NAME ==~ /(dev)/ }
}
steps {
echo 'Build Dockerfile....'
script {
sh("eval \$(aws ecr get-login --no-include-email --region eu-central-1 | sed 's|https://||')")
// sh "docker build --network=host -t $IMAGE -f deploy/docker/Dockerfile ."
sh "docker build --network=host -t $IMAGE ."
docker.withRegistry("https://$ECRURL"){
docker.image("$IMAGE").push("dev-$BUILD_NUMBER")
}
}
}
}
stage('Build For Staging Environment') {
when {
expression { BRANCH_NAME ==~ /(staging|master)/ }
}
steps {
echo 'Build Dockerfile....'
script {
sh("eval \$(aws ecr get-login --no-include-email --region eu-central-1 | sed 's|https://||')")
// sh "docker build --network=host -t $IMAGE -f deploy/docker/Dockerfile ."
sh "docker build --network=host -t $IMAGE ."
docker.withRegistry("https://$ECRURL"){
docker.image("$IMAGE").push("staging-$BUILD_NUMBER")
}
}
}
}
stage('Build For Production Environment') {
when { tag "release-*" }
steps {
echo 'Build Dockerfile....'
script {
sh("eval \$(aws ecr get-login --no-include-email --region eu-central-1 | sed 's|https://||')")
// sh "docker build --network=host -t $IMAGE -f deploy/docker/Dockerfile ."
sh "docker build --network=host -t $IMAGE ."
docker.withRegistry("https://$ECRURL"){
docker.image("$IMAGE").push("prod-$BUILD_NUMBER")
}
}
}
}
//
// stage('Update Helm appVersion') {
// steps {
// echo 'Update appVersion'
// sh '''
// cat helm/Chart.yaml.template | sed "s/appVersion: .*/appVersion: \"${BUILD_NUMBER}\"/g" > helm/Chart.yaml
// '''
// }
// }
}
post
{
always
{
sh "docker rmi -f $IMAGE "
}
}
}