-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
191 lines (191 loc) · 6.98 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
pipeline {
agent any
triggers {
pollSCM('H/30 * * * *')
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
}
environment {
sonarScannerHome = tool name: 'sonarScanner'
}
stages {
stage('NodeJS Build') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
}
}
steps {
sh 'npm install'
sh 'npm install --save-dev jenkins-mocha nyc gulp gulp-uglify'
}
post {
success {
echo 'Npm install worked!'
}
failure {
echo 'Npm install failed..'
}
}
}
stage('Gulp Tasks') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
}
}
steps {
sh 'node_modules/.bin/gulp scripts'
}
post {
success {
echo 'Gulp task completed!'
}
failure {
echo 'Gulp task failed..'
}
}
}
stage('Mocha/Istanbul') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
additionalBuildArgs '--tag autoopsltd/decnodetest:testing'
}
}
steps {
sh 'npm run test_jenkins'
}
post {
success {
echo 'Mocha testing worked!'
archiveArtifacts artifacts: 'dist/*.js'
junit '**/artifacts/**/*.xml'
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'coverage', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: ''])
}
failure {
echo 'Mocha testing failed..'
}
}
}
stage('Sonar Analyze/Quality Gate') {
agent any
steps {
withSonarQubeEnv('sonarqube') {
withCredentials([string(credentialsId: 'sonar', variable: 'sonarLogin')]) {
sh "${sonarScannerHome}/bin/sonar-scanner -e -Dsonar.host.url=http://192.168.1.15:9001 -Dsonar.login=${sonarLogin} -Dsonar.projectName=decNodeTest -Dsonar.projectVersion=${env.BUILD_NUMBER} -Dsonar.projectKey=NA -Dsonar.sources=. -Dsonar.language=js"
}
}
}
post {
success {
echo 'Sonar Quality Gate passed!'
}
failure {
echo 'Sonar Quality Gate failed..'
}
}
}
stage('Parallel Upload Artefacts') {
when {
branch 'master'
}
parallel {
stage('Upload to Nexus') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
additionalBuildArgs '--tag autoopsltd/decnodetest:testing'
}
}
steps {
sh 'npm --version'
sh './setup_nexus_repo.sh'
sh 'npm publish --registry http://192.168.1.15:8082/repository/npm-internal/'
sh 'rm -f .npmrc'
}
}
stage('Upload to Artifactory') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
additionalBuildArgs '--tag autoopsltd/decnodetest:testing'
}
}
steps {
script {
def server = Artifactory.server 'artifactory'
def uploadSpec = """{
"files": [
{
"pattern": "./dist/*.js",
"target": "generic-local/decNodeTest/",
"recursive": "false"
}
]
}"""
server.upload(uploadSpec)
def buildInfo1 = server.upload uploadSpec
server.publishBuildInfo buildInfo1
}
}
}
}
post {
success {
echo 'Artefact uploading worked!'
}
failure {
echo 'Artefact uploading failed..'
}
}
}
stage('Docker Tag/Push') {
steps {
withDockerRegistry([ credentialsId: "dockerhub", url: "http://localhost:5000"]) {
sh 'docker tag autoopsltd/decnodetest:testing localhost:5000/decnodetest:latest'
sh 'docker push localhost:5000/decnodetest:latest'
}
}
}
stage('Ansible Launch') {
agent any
steps {
sh '/usr/bin/ansible-playbook -i /root/ansible/inventory ./playbook.yml'
}
}
}
post {
always {
echo 'Pipeline processing completed.'
}
success {
echo "Pipeline job ${env.JOB_NAME} completed successfully with no errors."
mail to: '[email protected]',
from: '[email protected]',
subject: "Pipeline Successful : ${env.JOB_NAME}",
body: "Pipeline job ${env.JOB_NAME} from branch ${env.BRANCH_NAME} completed successfully. For further details visit ${env.BUILD_URL}."
}
failure {
echo "Pipeline job ${env.JOB_NAME} failed."
mail to: '[email protected]',
from: '[email protected]',
subject: "Pipeline Failure : ${env.JOB_NAME}",
body: "Pipeline job ${env.JOB_NAME} from branch ${env.BRANCH_NAME} failed. For further details visit ${env.BUILD_URL}."
}
unstable {
echo "Pipeline job ${env.JOB_NAME} completed but was declared unstable."
mail to: '[email protected]',
from: '[email protected]',
subject: "Pipeline Unstable : ${env.JOB_NAME}",
body: "Pipeline job ${env.JOB_NAME} from branch ${env.BRANCH_NAME} completed but was declared unstable. For further details visit ${env.BUILD_URL}."
}
}
}