Skip to content
This repository was archived by the owner on Jul 22, 2021. It is now read-only.

Commit 3a1131b

Browse files
authored
Added Jenkinsfile (#6)
* Added Jenkinsfile Added VERSION file. Added Jenkinsfile for build/test/publish.
1 parent 78a8264 commit 3a1131b

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

Jenkinsfile

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!groovy
2+
3+
/*
4+
* Copyright © 2017 IBM Corp. All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
7+
* except in compliance with the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software distributed under the
12+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
* either express or implied. See the License for the specific language governing permissions
14+
* and limitations under the License.
15+
*/
16+
17+
stage('Build') {
18+
// Checkout, build and assemble the source and doc
19+
node {
20+
checkout scm
21+
sh './gradlew clean assemble'
22+
stash name: 'built'
23+
}
24+
}
25+
26+
stage('Test') {
27+
node {
28+
// Unstash the built code
29+
unstash name: 'built'
30+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'clientlibs-test', usernameVariable: 'DB_USER', passwordVariable: 'DB_PASSWORD']]) {
31+
// Run the core and in-process tests
32+
// Note Redis server not available in this env, so those tests excluded (but tested by Travis CI)
33+
try {
34+
sh "./gradlew -Dtest.couch.url=https://${env.DB_USER}:${env.DB_PASSWORD}@clientlibs-test.cloudant.com :cloudant-client-cache:test :cloudant-client-cache-in-process:test"
35+
} finally {
36+
junit '**/build/test-results/*.xml'
37+
}
38+
}
39+
}
40+
}
41+
42+
// Publish the master branch
43+
stage('Publish') {
44+
if (env.BRANCH_NAME == "master") {
45+
node {
46+
checkout scm // re-checkout to be able to git tag
47+
unstash name: 'built'
48+
// read the version name and determine if it is a release build
49+
version = readFile('VERSION').trim()
50+
isReleaseVersion = !version.toUpperCase(Locale.ENGLISH).contains("SNAPSHOT")
51+
52+
// Upload using the ossrh creds (upload destination logic is in build.gradle)
53+
withCredentials([usernamePassword(credentialsId: 'ossrh-creds', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USER'), usernamePassword(credentialsId: 'signing-creds', passwordVariable: 'KEY_PASSWORD', usernameVariable: 'KEY_ID'), file(credentialsId: 'signing-key', variable: 'SIGNING_FILE')]) {
54+
sh './gradlew -Dsigning.keyId=$KEY_ID -Dsigning.password=$KEY_PASSWORD -Dsigning.secretKeyRingFile=$SIGNING_FILE -DossrhUsername=$OSSRH_USER -DossrhPassword=$OSSRH_PASSWORD upload'
55+
}
56+
57+
// if it is a release build then do the git tagging
58+
if (isReleaseVersion) {
59+
60+
// Read the CHANGES.md to get the tag message
61+
tagMessage = ''
62+
for (line in readFile('CHANGES.md').readLines()) {
63+
if (!''.equals(line)) {
64+
// append the line to the tagMessage
65+
tagMessage = "${tagMessage}${line}\n"
66+
} else {
67+
break
68+
}
69+
}
70+
71+
// Use git to tag the release at the version
72+
try {
73+
// Awkward workaround until resolution of https://issues.jenkins-ci.org/browse/JENKINS-28335
74+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'github-token', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
75+
sh "git config user.email \"[email protected]\""
76+
sh "git config user.name \"Jenkins CI\""
77+
sh "git config credential.username ${env.GIT_USERNAME}"
78+
sh "git config credential.helper '!echo password=\$GIT_PASSWORD; echo'"
79+
sh "git tag -a ${version} -m '${tagMessage}'"
80+
sh "git push origin ${version}"
81+
}
82+
} finally {
83+
sh "git config --unset credential.username"
84+
sh "git config --unset credential.helper"
85+
}
86+
}
87+
}
88+
}
89+
}

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.3.1-SNAPSHOT

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ subprojects {
1818
apply plugin: 'signing'
1919

2020
group = 'com.cloudant'
21-
version = '0.3.1-SNAPSHOT'
21+
version = new File(rootDir, 'VERSION').text.trim()
2222
description = """A Java object cache for use with the java-cloudant client"""
2323

2424
// If the version says "snapshot" anywhere assume it is not a release

0 commit comments

Comments
 (0)