-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
90 lines (81 loc) · 2.77 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
pipeline {
agent { label 'docker' }
environment {
PROJECT_VERSION = readMavenPom().getVersion()
}
stages {
stage('run tests') {
steps {
echo "branch ${env.BRANCH_NAME}"
echo "${PROJECT_VERSION}"
withMaven(
mavenSettingsConfig: '67c40a88-505a-4f78-94a3-d879cc1a29f6'
) {
sh 'mvn -U install'
}
}
}
stage('snapshot deploy') {
when {
expression { PROJECT_VERSION ==~ /.*-SNAPSHOT/ }
}
steps {
echo "deploying version ${PROJECT_VERSION}"
withMaven(
mavenSettingsConfig: '67c40a88-505a-4f78-94a3-d879cc1a29f6'
) {
sh 'mvn deploy -Dmaven.test.skip=true || echo $?'
}
}
}
stage('release deploy') {
when {
allOf {
branch 'main'
not { expression { PROJECT_VERSION ==~ /.*-SNAPSHOT/ } }
anyOf {
changeset 'pom.xml'
changeset 'src/*'
}
}
}
steps {
echo "deploying release version ${PROJECT_VERSION}"
withMaven(mavenSettingsConfig: '67c40a88-505a-4f78-94a3-d879cc1a29f6') {
sh 'mvn deploy -Dmaven.test.skip=true'
}
sshagent (credentials: ['cxp-bot']) {
sh "git tag v$PROJECT_VERSION"
sh 'git push --tags || echo "WARN: could not push tags, but build succeeded"'
}
}
}
}
post {
success {
setBuildStatus("Build succeeded", "SUCCESS")
}
failure {
setBuildStatus("Build failed", "FAILURE")
}
}
}
def getRepoURL() {
sh "git config --get remote.origin.url > .git/remote-url"
return readFile(".git/remote-url").trim()
}
def getCommitSha() {
sh "git rev-parse HEAD > .git/current-commit"
return readFile(".git/current-commit").trim()
}
void setBuildStatus(String message, String state) {
repoUrl = getRepoURL()
commitSha = getCommitSha()
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitSha],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}