-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile_build
104 lines (95 loc) · 3.21 KB
/
Jenkinsfile_build
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
pipeline {
agent any
stages {
stage('Send Start Alert') {
steps {
script {
// Get the user who launched the job
//wrap([$class: 'BuildUser']) {
// def user = env.BUILD_USER
//}
// Send start notification
telegramSend(
token: '5451305173:AAGSmRL_518hBsPx3N_Zih_cy0oeMbZhpyI',
chatId: '-688306623',
message: "The job RP1 Build and Test has started and is currently running."
)
}
}
}
// Building and Testing the application.
stage('Install') {
steps {
sh 'sudo apt-get update'
sh 'yes | sudo apt install docker.io curl && sudo snap install docker'
echo 'necessary updates and installation completed>>>'
}
}
stage('Build') {
steps {
sh 'docker rm -f sne22-webapp'
echo 'redundant container check passed!'
sh 'docker build -t my-webapp .'
echo 'build completed>>>'
}
}
// Testing the container run-time
stage('Test') {
steps {
sh 'docker run -d --name sne22-webapp -p 9000:9000 my-webapp'
echo 'container test deployment was successfull>>>'
}
}
// Security scan using Snyk
stage('Security Scan') {
steps {
snykSecurity additionalArguments: '--docker my-webapp',failOnError: false, failOnIssues: false, snykInstallation: 'Snyk', snykTokenId: 'Snyk-Jenkins', targetFile: 'Dockerfile'
}
}
// Pushing application and it's artifacts to container repository
stage('Push') {
steps {
echo 'now pushing working image to dockerhub...'
sh 'docker login -u rp1sne22 -p dckr_pat_gi6co2PnC5xTtoElVINANoHAAt4 docker.io'
sh 'docker tag my-webapp rp1sne22/my-webapp:latest'
sh 'docker push rp1sne22/my-webapp:latest'
echo 'container image push was successfull>>>'
}
}
// Deleting the container from the jenkins agent node
stage('Cleanup') {
steps {
echo 'initializing test server cleanup...'
sh 'docker rm -f $(docker ps -a -q)'
echo 'removed container runtime'
sh 'docker image prune'
echo 'removed docker image'
}
}
}
// Sending Notification upon job completion
post {
success {
script {
// Send success notification
telegramSend(
token: '5451305173:AAGSmRL_518hBsPx3N_Zih_cy0oeMbZhpyI',
chatId: '-688306623',
message: "The job RP1 Build and Test has completed successfully."
)
}
}
failure {
script {
// Get the cause of the failure
def failureCause = currentBuild.getResult().toString()
// Send failure notification
telegramSend(
token: '5451305173:AAGSmRL_518hBsPx3N_Zih_cy0oeMbZhpyI',
chatId: '-688306623',
message: "The job RP1 Build and Test has failed due to ${failureCause}."
)
}
}
}
}