-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
75 lines (73 loc) · 2.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
pipeline {
agent any
environment {
SCANNER_HOME=tool 'sonar-scanner'
DOCKER_TAG_IMAGE = "soravkumarsharma/tictactoe:latest"
}
stages {
stage('Clean WorkSace') {
steps {
cleanWs()
}
}
stage('Git Checkout') {
steps {
git branch: 'main', url: 'https://github.com/soravkumarsharma/TIC-TAC-TOE-DevSecOps-Project.git'
}
}
stage('Static Code Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=TicTacToe \
-Dsonar.projectKey=TicTacToe'''
}
}
}
stage('Quality Gate') {
steps {
script {
timeout(5) {
def qg = waitForQualityGate()
if (qg.status != 'OK'){
error "Pipeline aborted due to Quality Gate failure: ${qg.status}"
}
}
}
}
}
stage('File System Scan - Trivy') {
steps {
sh "trivy fs . > fs_report.txt"
}
}
stage('Docker Build') {
steps {
script {
withDockerRegistry(credentialsId: 'dockerhub', toolName: 'docker') {
sh "docker build -t tictactoe ."
sh "docker tag tictactoe ${DOCKER_TAG_IMAGE}"
}
}
}
}
stage('Docker Image Scan') {
steps {
sh "trivy image ${DOCKER_TAG_IMAGE} > image_report.txt"
}
}
stage('Docker Push') {
steps {
script {
withDockerRegistry(credentialsId: 'dockerhub', toolName: 'docker') {
sh "docker push ${DOCKER_TAG_IMAGE}"
}
}
}
}
stage('Deploy to Container') {
steps {
sh "docker run -d -p 3000:3000 ${DOCKER_TAG_IMAGE}"
}
}
}
}