forked from NVISOsecurity/ee-outliers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
150 lines (136 loc) · 5.45 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
146
147
148
149
150
def latest_tag
def version_tag
def feature_version_tag
def push_images
pipeline {
options{
disableConcurrentBuilds()
office365ConnectorWebhooks([[
notifyBackToNormal: true,
notifyFailure: true,
notifyRepeatedFailure: true,
notifySuccess: false,
notifyUnstable: true,
url: "${env.TEAMS_WEBHOOK}"
]])
}
agent { label 'docker' }
stages {
stage('Clone repository') {
steps {
checkout scm
}
}
stage('Prepare version tags') {
steps {
script {
env.WORKSPACE = pwd()
def version = readFile "${env.WORKSPACE}/VERSION"
def feature_version = version.split("\\.")[0..1].join(".")
version = version.trim()
if(env.BRANCH_NAME == 'master') {
latest_tag = "latest"
version_tag = "${version}"
feature_version_tag = "${feature_version}"
push_images = "true"
}
else if(env.BRANCH_NAME == 'development') {
latest_tag = "devlatest"
version_tag = "${version}-dev"
feature_version_tag = "${feature_version}-dev"
push_images = "true"
}
else if(env.BRANCH_NAME =~ /^release-[\d\.]+$/) {
latest_tag = "rclatest"
version_tag = "${version}RC${env.BUILD_NUMBER}"
feature_version_tag = "${feature_version}RC${env.BUILD_NUMBER}"
push_images = "true"
}
else if(env.BRANCH_NAME =~ /^feature-.*$/) {
latest_tag = env.BRANCH_NAME
version_tag = env.BRANCH_NAME
feature_version_tag = env.BRANCH_NAME
push_images = "true"
} else {
latest_tag = env.BRANCH_NAME
version_tag = env.BRANCH_NAME
feature_version_tag = env.BRANCH_NAME
push_images = "false"
}
}
}
}
stage('Build docker image') {
steps {
script {
if(env.NO_CACHE == "1") {
app = docker.build("eagleeye/outliers:${latest_tag}", "--no-cache .")
} else {
app = docker.build("eagleeye/outliers:${latest_tag}")
}
}
}
}
stage('Test image') {
steps {
script {
app.inside {
sh 'python3 /app/outliers.py tests --config /defaults/outliers.conf --use-cases /app/tests/files/use_cases/*.conf'
}
}
}
}
stage('Sonarqube analysis') {
steps {
script{
env.VERSION = version_tag
def scannerHome = tool 'sonarscanner';
withSonarQubeEnv('Sonar') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
stage("Quality Gate") {
steps {
timeout(time: 30, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
stage('Push image') {
steps {
script {
if (env.BRANCH_NAME == 'master') {
sshagent (credentials: ['GithubSSHKey']) {
sh '''
git tag $(cat VERSION)
git push origin --tags
'''
}
}
if (push_images == 'true') {
docker.withRegistry("${env.DOCKER_REGISTRY_URL}", 'jenkins-nexus') {
app.push("${version_tag}")
app.push("${feature_version_tag}")
app.push("${latest_tag}")
}
}
if(env.BRANCH_NAME == 'master') {
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh """
docker tag eagleeye/outliers:latest nvisobe/ee-outliers:${latest_tag};
docker tag eagleeye/outliers:latest nvisobe/ee-outliers:${version_tag};
docker tag eagleeye/outliers:latest nvisobe/ee-outliers:${feature_version_tag};
docker login --username=$USERNAME --password=$PASSWORD;
docker push nvisobe/ee-outliers:${latest_tag};
docker push nvisobe/ee-outliers:${version_tag};
docker push nvisobe/ee-outliers:${feature_version_tag};
"""
}
}
}
}
}
}
}