forked from natalka1122/epam-diploma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
115 lines (112 loc) · 3.19 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
import groovy.transform.Field
@Field def image_names
@Field def image_build
@Field def registry_credential_set
pipeline {
agent any
environment {
TOKEN = credentials('botSecret')
CHAT_ID = credentials('chatId')
}
stages {
stage('init vars') {
steps{
script {
image_names = ['frontend', 'backend']
image_build = []
registry_credential_set = 'dockerhub'
}
}
}
stage('build'){
agent {
node {
label 'proxmox'
}
}
steps {
script {
withCredentials([usernamePassword(credentialsId: registry_credential_set, passwordVariable: 'password', usernameVariable: 'username')]) {
for (int i = 0; i < image_names.size(); i++) {
image_build.add(docker.build("${username}/${image_names[i]}","--build-arg SOURCE_DIR=${image_names[i]}/ ."))
}
}
}
}
}
stage('Test') {
agent {
node {
label 'proxmox'
}
}
steps {
script {
for (int i = 0; i < image_build.size(); i++) {
image_build[i].inside('-u root'){
sh 'apk add --update gcc libc-dev'
sh 'pip install --upgrade pylint black'
sh 'cd /app && python3 -m pylint *.py --output-format=parseable --fail-under=9 --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}"| tee pylint.log'
sh 'cd /app && python3 -m black *.py --diff'
sh 'cd /app && python3 -m black *.py --check'
}
}
}
}
}
stage('push images') {
agent {
node {
label 'proxmox'
}
}
steps {
script {
docker.withRegistry('', registry_credential_set) {
for (int i = 0; i < image_build.size(); i++) {
image_build[i].push()
}
}
}
}
}
stage('dev environment') {
agent {
node {
label 'proxmox'
}
}
steps {
sh 'docker-compose down'
sh 'docker-compose up -d'
}
}
stage('Ready for prod?') {
steps {
input message: "Are we ready for prod?"
}
}
stage('Deploy to prod') {
steps {
echo "Kubernetes"
}
}
}
post {
success {
node('java-docker-slave') {
sh 'wget -qO- --post-data="parse_mode=markdown&chat_id=' + CHAT_ID + '&text=*' + env.JOB_NAME+ '* : POC *Branch*: ' + env.GIT_BRANCH + ' *Build* : OK *Published* = YES" https://api.telegram.org/bot' + TOKEN + '/sendMessage'
}
}
aborted {
node('java-docker-slave') {
sh 'wget -qO- --post-data="parse_mode=markdown&chat_id=' + CHAT_ID + '&text=*' + env.JOB_NAME+ '* : POC *Branch*: ' + env.GIT_BRANCH + ' *Build* : Aborted *Published* = Aborted" https://api.telegram.org/bot' + TOKEN + '/sendMessage'
}
}
failure {
node('java-docker-slave') {
sh 'wget -qO- --post-data="parse_mode=markdown&chat_id=' + CHAT_ID + '&text=*' + env.JOB_NAME+ '* : POC *Branch*: ' + env.GIT_BRANCH + ' *Build* : not OK *Published* = NO" https://api.telegram.org/bot' + TOKEN + '/sendMessage'
}
}
}
}