-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
99 lines (95 loc) · 3.56 KB
/
Jenkinsfile
File metadata and controls
99 lines (95 loc) · 3.56 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
properties([
parameters([
booleanParam(
defaultValue: false
, description: 'Runs release step'
, name: 'RELEASE')
])
])
node {
deleteDir()
checkout scm
def mvnHome = tool 'maven-3.5.0'
withEnv(["M2_HOME=$mvnHome", "PATH+MAVEN=$mvnHome/bin"]) {
try {
stage('Build') {
def project = readMavenPom file: ''
echo "Building ${project.artifactId} - ${project.version} ..."
sh 'command -V mvn'
sh 'mvn --batch-mode -V -U clean install -DskipTests -DskipITs'
}
stage('Test') {
echo 'Testing....'
try {
wrap([$class: 'Xvnc']) {
sh 'mvn --batch-mode verify'
}
} finally {
junit testResults: 'target/surefire-reports/*.xml', allowEmptyResults: true
junit testResults: 'target/failsafe-reports/*.xml', allowEmptyResults: true
}
}
stage('Test-Release') {
echo 'Release Dry Run....'
sh 'mvn --batch-mode release:prepare -DdryRun=true -Darguments="-DskipTests -DskipITs"'
sh 'mvn --batch-mode release:clean'
}
if(BRANCH_NAME == 'master') {
milestone()
stage('Deploy-Maven') {
echo 'Deploying maven artifact...'
sh "mvn --batch-mode deploy -DskipTests -DskipITs"
}
milestone()
lock(resource: 'docker') {
stage(name: 'Deploy-Docker') {
echo 'Deploying....'
docker.withRegistry("http://localhost:5000") {
def image = docker.build("vertx-mindmap:${env.BRANCH_NAME}")
image.push("${env.BRANCH_NAME}")
}
}
}
}
} catch (ex) {
closePullRequest()
throw ex
}
if (params.RELEASE) {
stage('Release') {
echo 'Releasing...'
sh 'git checkout master'
def project = readMavenPom file: ''
echo "before ${project.version}"
sh 'mvn --batch-mode -Dresume=false release:prepare release:perform -Darguments="-DskipTests -DskipITs"'
def after = readMavenPom file: ''
echo "after ${after.version}"
createPostBuildBranch(project)
}
}
}
}
def closePullRequest() {
if(env.CHANGE_ID != null) {
def patchBody = """ {"state": "closed"} """
httpRequest(
acceptType: 'APPLICATION_JSON'
, contentType: 'APPLICATION_JSON'
, authentication: 'hwvenancio-github'
, httpMode: 'PATCH'
, requestBody: patchBody
, url: "https://api.github.com/repos/hwvenancio/vertx-mindmap/pulls/${env.CHANGE_ID}")
}
}
def createPostBuildBranch(project) {
def tagVersion = project.version.replace('-SNAPSHOT', '')
def tagName = "${project.artifactId}-${tagVersion}"
def pbVersion = project.version.replace('-SNAPSHOT', '.1-SNAPSHOT')
def pbBranch = tagVersion + ".X"
sh """
git checkout -b $pbBranch $tagName
mvn release:update-versions -DdevelopmentVersion=$pbVersion
git add pom.xml
mvn scm:checkin -Dmessage="[jenkins-pipeline] prepare post-build branch $pbBranch"
"""
}