forked from devsecblueprint/devsecblueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
101 lines (98 loc) · 3.87 KB
/
Copy pathJenkinsfile
File metadata and controls
101 lines (98 loc) · 3.87 KB
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
// For Damien's Personal Homelab
pipeline {
agent any
environment {
KUBECONFIG = '/home/jenkins/.kubeconfig'
GIT_SSL_NO_VERIFY = 'true'
SONAR_TOKEN = credentials('sonar-analysis')
SONAR_PROJECT_KEY = 'devsecblueprint.github.io'
DOCKER_IMAGE_NAME = 'devsecblueprint'
NEXUS_DOCKER_PUSH_INDEX = 'nexus-dockerhost.dsb-hub.local'
NEXUS_DOCKER_PUSH_PATH = 'repository/docker-host'
GOOGLE_ANALYTICS_ID = "test"
GOOGLE_TAG_MANAGER_ID = "test"
}
options {
disableConcurrentBuilds()
}
stages {
stage('Clone') {
steps {
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'Gitea PAT', url: 'https://dsb-hub.local/damien/devsecblueprint.github.io.git']])
}
}
stage('Build') {
steps {
sh """
echo "GOOGLE_ANALYTICS_ID=${GOOGLE_ANALYTICS_ID}" > .env
echo "GOOGLE_TAG_MANAGER_ID=${GOOGLE_TAG_MANAGER_ID}" >> .env
cat .env
"""
sh 'docker build -t ${DOCKER_IMAGE_NAME}:${BUILD_NUMBER} .'
}
}
stage('Security Scan'){
parallel {
stage('Sonar Scan') {
steps {
script {
try{
withSonarQubeEnv(installationName: 'Sonar Server', credentialsId: 'sonar-analysis') {
sh '''
docker run --rm \
-e SONAR_HOST_URL="${SONAR_HOST_URL}" \
-e SONAR_TOKEN="${SONAR_TOKEN}" \
-v "$(pwd):/usr/src" \
${NEXUS_DOCKER_PUSH_INDEX}/repository/docker-host/sonar-scanner-cli \
-Dsonar.projectKey="${SONAR_PROJECT_KEY}" \
-Dsonar.qualitygate.wait=true \
-Dsonar.sources=.
'''
}
} catch (Exception e) {
// Handle the error
echo "Quality Qate check has failed: ${e}"
currentBuild.result = 'UNSTABLE' // Mark the build as unstable instead of failing
}
}
}
}
stage('Security Scan') {
steps {
sh '''
trivy image --severity HIGH,CRITICAL ${DOCKER_IMAGE_NAME}:${BUILD_NUMBER}
'''
}
}
}
}
stage('Publish') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'nexus', passwordVariable: 'NEXUS_PASSWORD', usernameVariable: 'NEXUS_USERNAME')]) {
sh """
docker login ${NEXUS_DOCKER_PUSH_INDEX} -u $NEXUS_USERNAME -p $NEXUS_PASSWORD
docker tag ${DOCKER_IMAGE_NAME}:${BUILD_NUMBER} ${NEXUS_DOCKER_PUSH_INDEX}/${NEXUS_DOCKER_PUSH_PATH}/${DOCKER_IMAGE_NAME}:latest
docker push ${NEXUS_DOCKER_PUSH_INDEX}/${NEXUS_DOCKER_PUSH_PATH}/${DOCKER_IMAGE_NAME}:latest
"""
}
}
}
}
stage('Deploy') {
steps {
script {
echo 'Deploying to DSB Node 01'
sh '''
helm upgrade --install ${DOCKER_IMAGE_NAME} ./helm/
'''
}
}
}
}
post {
always {
cleanWs()
}
}
}