forked from SNE22-INNOPOLIS/RP1-CODEBASE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile_build
61 lines (54 loc) · 1.78 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
pipeline {
agent any
stages {
// Building and Testing the application.
stage('Install') {
steps {
sh 'sudo apt-get update'
sh 'sudo apt install docker.io -y && 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'
}
}
}
}