-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
136 lines (123 loc) · 4.3 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
pipeline {
// https://medium.com/@gustavo.guss/jenkins-building-docker-image-and-sending-to-registry-64b84ea45ee9
// https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/gitcommit/gitcommit.groovy
agent any
// agent {
// kubernetes {
// cloud 'leon-build-cluster-dev'
// label "${JOB_BASE_NAME}-${BUILD_NUMBER}"
// yamlFile 'devops/pipeline/agent.yaml'
// }
// }
// options {
// disableConcurrentBuilds()
// gitLabConnection('gitlab.leoncorp.net')
// }
// environment {
// SLACK_CHANNEL = '#traffic-panel-internal'
// SLACK_TOKEN = 'n428BZEvAjBNRjk5DN5cvvv8'
// }
stages {
stage('init') {
steps {
sh 'whoami && pwd && ls -la && printenv | sort'
// script {
// if (isMergeRequest()) {
// updateGitlabCommitStatus state: 'running'
// }
// }
}
}
// stage('lint') {
// steps {
// sh './gradlew spotlessCheck'
// }
// }
stage('build') {
steps {
sh './gradlew assemble'
}
}
stage('test') {
steps {
sh './gradlew test'
}
post {
always {
// NEED TO INSTALL HTLMPublisher Jenkins plugin first
// https://stackoverflow.com/questions/50649363/no-such-dsl-method-publishhtml-found-among-steps
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true,
reportDir : "build/reports/tests/test", reportFiles: 'index.html',
reportName : "Unit Tests Report", reportTitles: ''])
}
}
}
stage('integration tests') {
steps {
sh './gradlew integrationTest'
}
post {
always {
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true,
reportDir : "build/reports/tests/integrationTest", reportFiles: 'index.html',
reportName : "Integration Tests Report", reportTitles: ''])
}
}
}
// https://jenkins.io/doc/book/pipeline/docker/#custom-registry
stage('docker') {
environment {
REGISTRY = "ilja07/country-phone"
DOCKER_IMAGE = 'country-phone'
DOCKER_TAG = sh(returnStdout: true, script: "git rev-parse --short=8 HEAD").trim()
}
when {
branch 'master'
}
steps {
script {
def image = docker.build("${REGISTRY}", '-f Dockerfile .')
// image.push("${DOCKER_TAG}")
// image.push()
//docker-hub-credentials needs to be added manually via Jenkins UI -> Credentials -> Jenkins global
docker.withRegistry('https://registry-1.docker.io/v2/', 'dockerhub') {
image.push("${DOCKER_TAG}")
// image without tag - is LATEST by default
image.push()
}
}
}
}
// post {
// always {
// notifySlack(getCommitMsg(), currentBuild.currentResult)
// }
// aborted {
// script {
// if (isMergeRequest()) {
// updateGitlabCommitStatus state: 'canceled'
// }
// }
// }
// failure {
// script {
// if (isMergeRequest()) {
// updateGitlabCommitStatus state: 'failed'
// }
// }
// }
// success {
// script {
// if (isMergeRequest()) {
// updateGitlabCommitStatus state: 'success'
// }
// }
// }
// }
}
//?FUNCTIONS? - https://stackoverflow.com/questions/47628248/how-to-create-methods-in-jenkins-declarative-pipeline/47631522
// def showMavenVersion(String a) {
// bat 'mvn -v'
// echo a
// }
}