-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
62 lines (58 loc) · 1.93 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
#!groovy
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()
}
def getSnapshot(){
if (env.BRANCH_NAME == "main") {
return ""
}
return "-".concat(env.BRANCH_NAME).concat("-SNAPSHOT")
}
void setBuildStatus(String message, String state) {
repoUrl = getRepoURL()
commitSha = getCommitSha()
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/build-status"],
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitSha],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
])
};
pipeline {
agent {
docker {
image 'maven:3-eclipse-temurin-8'
args '-v /home/jenkins:/home/jenkins'
}
}
stages {
stage ('Init') {
steps {
checkout scm
setBuildStatus("Build started", "PENDING")
}
}
stage('Build') {
steps {
sh "sed -i -e \"s/\\\${snapshot}/".concat(getSnapshot()).concat("/g\" pom.xml")
withCredentials([usernamePassword(credentialsId: 'c0d3m4513r-deployment', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
sh 'mvn -B --settings settings.xml clean deploy -Dusername=$USERNAME -Dpassword=$PASSWORD'
}
}
}
}
post {
success {
setBuildStatus("Build succeeded", "SUCCESS");
}
failure {
setBuildStatus("Build failed", "FAILURE");
}
}
}