-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-multibranch
136 lines (110 loc) · 4.12 KB
/
Jenkinsfile-multibranch
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
// for dependency tracker needs OWASP Dependency-Check Plugin
// for multibranch webhook needs Multibranch Scan Webhook Trigger
// for multibranch to keep file in diffrent repo https://plugins.jenkins.io/remote-file/
pipeline{
agent any
stages{
stage("System-ENVS") {
steps{
sh 'printenv | sort'
}
}
stage("Set variables according to env"){
steps{
script{
if (env.GIT_BRANCH == 'main'){
app_name = 'web-app-prod'
artifactory = 'webapp/prod'
server = 'prod-server'
}
if (env.GIT_BRANCH == 'dev'){
app_name = 'web-app-dev'
artifactory = 'webapp/dev'
server = 'dev-server'
}
}
}
}
stage('Dependancy tracker check'){
steps{
script{
dependencyCheck additionalArguments: ''' --scan ./web-app''', odcInstallation: 'Dep-checkk'
dependencyCheckPublisher failedTotalCritical: 1, pattern: '', stopBuild: true, unstableTotalCritical: 1
}
}
}
// need to setup sonarqube plugins,connector,server,project and project-key
stage('SonarQube Analysis') {
steps{
script{
def scannerHome = tool name: 'scanner-name', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
withSonarQubeEnv('sonar') {
sh "echo $pwd"
sh "${scannerHome}/bin/sonar-scanner \
-D sonar.projectKey=py-scan \
-D sonar.sourceEncoding=UTF-8 \
-D sonar.language=python "
// -D sonar.host.url=http://<URL>:9000"
// sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
// Need to create webhook in sonarqube
stage("SonarQube Quality Gate Check") {
steps {
script {
def qualityGate = waitForQualityGate()
if (qualityGate.status != 'OK') {
echo "${qualityGate.status}"
error "Quality Gate failed: ${qualityGateStatus}"
}
else {
echo "${qualityGate.status}"
echo "SonarQube Quality Gates Passed"
}
}
}
}
stage('Build Image'){
steps{
script{
docker.build ("${app_name}:${env.BUILD_ID}", "./web-app")
}
}
}
stage('Push Image to artifactory'){
steps{
script{
sh """
echo 'Image pushed to:${artifactory}'
"""
// sh "echo Image pushed to:${artifactory}"
}
}
}
stage('Deployment app'){
steps{
script{
if (env.GIT_BRANCH == 'main'){
input message: 'Please chech and approve for prod deployment', submitter: 'admin', submitterParameter: 'apporve_by_admin'
sh """
echo 'Application Deployed TO:${server}'
"""
}
else{
sh """
echo 'Application Deployed TO:${server}'
"""
}
}
}
}
}
post{
always{
cleanWs()
sh "docker system prune -f -a"
}
}
}