-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
76 lines (71 loc) · 2.35 KB
/
Jenkinsfile
File metadata and controls
76 lines (71 loc) · 2.35 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
pipeline {
agent {
label 'master'
}
tools {
jdk 'default'
}
environment {
VERSION = readFile("${WORKSPACE}/version.txt").trim()
}
stages {
stage('create-tag') {
when {
branch 'main'
}
steps {
script {
withCredentials([gitUsernamePassword(credentialsId: 'github-http', gitToolName: 'Default')]) {
// Clear all tags locally and fetch from origin. If pushing a tag fails for some reason, it will
// continue to exist in jenkins even though it won't be present in origin
sh "git tag | xargs git tag -d"
sh "git fetch --tags"
sh "git tag -a v${env.VERSION} -m \"espresso version v${env.VERSION}\""
}
}
}
}
stage('build') {
steps {
script {
sh "./gradlew clean build"
}
}
post {
always {
archiveArtifacts allowEmptyArchive: true,
artifacts: '**/reports/tests/**'
}
}
}
// Note: tagging stage MUST come before publishing to prevent a new artifact from overwriting an existing
// artifact for a specific version. Tagging will fail if you attempt to duplicate a tag, and prevents a duplicated
// artifact from being published
stage('push-tag') {
when {
branch 'main'
}
steps {
script {
withCredentials([gitUsernamePassword(credentialsId: 'github-http', gitToolName: 'Default')]) {
sh "git push origin v${env.VERSION}"
}
}
}
}
stage('publish') {
when {
branch 'main'
}
steps {
script {
withCredentials([
usernamePassword(credentialsId: 'sonatype-creds', usernameVariable: 'SONATYPE_USERNAME', passwordVariable: 'SONATYPE_PASSWORD')
]) {
sh "./gradlew publish"
}
}
}
}
}
}