-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.1st
118 lines (118 loc) · 4.39 KB
/
Jenkinsfile.1st
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
pipeline {
agent any
triggers {
pollSCM('H/30 * * * *')
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
}
environment {
sonarScannerHome = tool name: 'sonarscanner'
}
stages {
stage('npm build') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
additionalBuildArgs '--tag autoopsltd/ltest:testing'
}
}
steps {
sh 'npm install'
sh 'npm install --save-dev jenkins-mocha nyc'
}
post {
success {
echo 'NPM install worked.'
}
failure {
echo 'NPM install failed'
}
}
}
stage('mocha/istanbul') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
additionalBuildArgs '--tag autoopsltd/ltest:testing'
}
}
steps {
sh 'npm run test_jenkins'
}
post {
success {
echo 'Mocha/Istanbul testing worked.'
archiveArtifacts artifacts: 'app/*.js'
junit '**/artifacts/**/*.xml'
//publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'coverage', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: ''])
publishHTML([reportDir: 'coverage', reportFiles: 'index.html', reportName: 'Istanbul', reportTitles: '', keepAll: false, alwaysLinkToLastBuild: false, allowMissing: false])
}
failure {
echo 'Mocha/Istanbul testing failed'
}
}
}
stage('sonarqube') {
agent any
steps {
withSonarQubeEnv('sonarqube') {
withCredentials([string(credentialsId: 'sonar', variable: 'sonarLogin')]) {
sh "${sonarScannerHome}/bin/sonar-scanner -e -Dsonar.host.url=http://192.168.1.17:9000 -Dsonar.login=${sonarLogin} -Dsonar.projectName=ltest -Dsonar.projectVersion=${env.BUILD_NUMBER} -Dsonar.projectKey=NA -Dsonar.sources=. -Dsonar.language=js"
}
}
}
post {
success {
echo 'Sonar scan & quality gate testing worked.'
}
failure {
echo 'Sonar scan & quality gate testing failed.'
}
}
}
stage('ansible launch') {
agent any
steps {
sh 'ansible-playbook -i /root/ansible/inventory ./playbook.yml'
}
post {
success {
echo 'Ansible playbook ran successfully.'
}
failure {
echo 'Ansible playbook run failed.'
}
}
}
}
post {
always {
echo 'Jenkins job finished processing'
}
success {
echo "Jenkins job ${env.JOB_NAME} completed successfully"
mail to: '[email protected]',
from: '[email protected]',
subject: "Jenkins job ${env.JOB_NAME} completed successfully",
body: "Pipeline job ${env.JOB_NAME} from branch ${env.BRANCH_NAME} completed successfully. For more details visit: ${env.BUILD_URL}"
}
failure {
echo "Jenkins job ${env.JOB_NAME} failed"
mail to: '[email protected]',
from: '[email protected]',
subject: "Jenkins job ${env.JOB_NAME} failed",
body: "Pipeline job ${env.JOB_NAME} from branch ${env.BRANCH_NAME} failed. For more details visit: ${env.BUILD_URL}"
}
unstable {
echo "Jenkins job ${env.JOB_NAME} is unstable"
mail to: '[email protected]',
from: '[email protected]',
subject: "Jenkins job ${env.JOB_NAME} is unstable",
body: "Pipeline job ${env.JOB_NAME} from branch ${env.BRANCH_NAME} is unstable. For more details visit: ${env.BUILD_URL}"
}
}
}