-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
109 lines (97 loc) · 3.63 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
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
pipeline {
agent any
environment {
SONARQUBE_URL= "http://sonarqube:9000"
SONARQUBE_PROJECT_KEY = "example"
DB_HOST = "mysql"
DB_USERNAME = "root"
DB_PASSWORD = "admin"
DB_DATABASE = "test_example"
DOCKER_REPO = "ismaelalvesdoc/express-example"
}
stages {
stage('Checkout Code') {
steps {
git branch: 'master',
credentialsId: 'gogs',
url: 'http://gogs:3000/root/example'
sh "ls -lat"
}
}
stage('Build') {
steps {
sh 'npm i'
}
}
stage('Test') {
parallel {
stage ('Lint') {
steps {
sh 'npm run lint'
}
}
stage ('Jest') {
steps {
sh 'npm run test:coverage'
}
post {
always {
step([$class: 'CoberturaPublisher', coberturaReportFile: 'coverage/cobertura-coverage.xml'])
}
}
}
}
}
stage('Code Quality SonarQube') {
steps {
script {
withCredentials([string(credentialsId: 'sonarqube', variable: 'LOGIN')]) {
def scannerHome = tool 'sonarqube-scanner';
withSonarQubeEnv("sonarqube-container") {
sh "${tool("sonarqube-scanner")}/bin/sonar-scanner \
-Dsonar.projectKey=$SONARQUBE_PROJECT_KEY \
-Dsonar.sources=. \
-Dsonar.css.node=. \
-Dsonar.host.url=$SONARQUBE_URL \
-Dsonar.sourceEncoding='UTF-8' \
-Dsonar.javascript.lcov.reportPaths='coverage/lcov.info' \
-Dsonar.login=$LOGIN"
}
}
}
}
}
stage('Deploy Docker') {
steps {
withCredentials([usernamePassword(credentialsId: 'docker', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login --username $USERNAME --password $PASSWORD'
sh 'docker build -t $DOCKER_REPO -t $DOCKER_REPO:0.1.0 .'
sh 'docker push $DOCKER_REPO && docker push $DOCKER_REPO:0.1.0'
}
}
post {
always {
sh 'docker rmi --force $(docker images -q --filter "dangling=true") > /dev/null 2>&1'
}
}
}
}
post {
success {
emailext body: 'ALTERATIONS: ${CHANGES}',
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
subject: 'Build Sucess Jenkins: $JOB_NAME - #$BUILD_NUMBER'
}
failure {
emailext body: '''
Check console output at $BUILD_URL to view the results.
-------------------------------------------------
${CHANGES}
-------------------------------------------------
${BUILD_LOG, maxLines=100, escapeHtml=false}
''',
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
subject: 'Build failed Jenkins: $JOB_NAME - #$BUILD_NUMBER'
}
}
}