-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
92 lines (83 loc) · 3.37 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
pipeline {
agent any
environment {
DOCKER_NAMESPACE = '4everhosting'
DOCKER_IMAGE_NAME = 'webshot'
DOCKER_IMAGE = ''
DEPLOY_IMAGE_NAME = ''
DOCKER_HUB_HOST= ''
}
stages {
stage("Chose Environment") {
parallel {
stage('Dev') {
when {
environment name: 'APP_ENV', value: 'DEV'
}
stages {
stage('build image') {
steps {
script {
DOCKER_IMAGE = docker.build DOCKER_NAMESPACE + "/" + DOCKER_IMAGE_NAME
DEPLOY_IMAGE_NAME = DOCKER_NAMESPACE + "/" + DOCKER_IMAGE_NAME + ":" + env.GIT_COMMIT.substring(0, 8)
}
}
}
stage('push image') {
steps {
script {
docker.withRegistry(env.DOCKER_HUB_DEV_URL, env.DOCKER_HUB_DEV_CREDENTIAL) {
DOCKER_IMAGE.push(env.GIT_COMMIT.substring(0, 8))
}
}
}
}
stage('remove image') {
steps {
script {
DOCKER_HUB_HOST = env.DOCKER_HUB_DEV_URL.replaceAll("https://", "").replaceAll("http://", "")
sh "docker rmi ${DOCKER_NAMESPACE}/${DOCKER_IMAGE_NAME}"
sh 'docker rmi ' + DOCKER_HUB_HOST + DEPLOY_IMAGE_NAME
sh 'docker image prune -f --filter label=stage=screenshotbuilder'
}
}
}
}
}
stage('Prod') {
when {
environment name: 'APP_ENV', value: 'PROD'
}
steps {
echo 'Prod TODO'
}
}
}
}
stage('Deploy') {
steps {
script {
def body = '''
{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "''' + DOCKER_IMAGE_NAME + '''",
"image": "''' + DOCKER_HUB_HOST + DEPLOY_IMAGE_NAME + '''"
}
]
}
}
}
}
'''
response = httpRequest consoleLogResponseBody: true, contentType: 'NOT_SET',
httpMode: 'PATCH', requestBody: body, url: env.K8S_DEPLOY_API_URL, validResponseCodes: '200',
customHeaders: [[name: 'Content-Type', value: "application/strategic-merge-patch+json"]]
}
}
}
}
}