|
| 1 | +#!groovy |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright © 2016 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('QA') { |
| 27 | + parallel( |
| 28 | + Java: |
| 29 | + { |
| 30 | + node { |
| 31 | + unstash name: 'built' |
| 32 | + // findBugs |
| 33 | + try { |
| 34 | + sh './gradlew -Dfindbugs.xml.report=true findbugsMain' |
| 35 | + } finally { |
| 36 | + step([$class: 'FindBugsPublisher', pattern: '**/build/reports/findbugs/*.xml']) |
| 37 | + } |
| 38 | + // tests |
| 39 | + withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'clientlibs-test', usernameVariable: 'DB_USER', passwordVariable: 'DB_PASSWORD']]) { |
| 40 | + try { |
| 41 | + sh './gradlew -Dtest.with.specified.couch=true -Dtest.couch.username=$DB_USER -Dtest.couch.password=$DB_PASSWORD -Dtest.couch.host=clientlibs-test.cloudant.com -Dtest.couch.port=443 -Dtest.couch.http=https -Dtest.couch.ignore.compaction=true -Dtest.couch.ignore.auth.headers=true integrationTest' |
| 42 | + } finally { |
| 43 | + junit '**/build/test-results/*.xml' |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + }, |
| 48 | + Android: |
| 49 | + { |
| 50 | + node('android') { |
| 51 | + unstash name: 'built' |
| 52 | + try { |
| 53 | + sh './gradlew -Dtest.with.specified.couch=true -Dtest.couch.host=cloudantsync002.bristol.uk.ibm.com -Dtest.couch.port=5984 -Dtest.couch.ignore.compaction=true -Dtest.couch.ignore.auth.headers=true -b AndroidTest/build.gradle uploadFixtures connectedCheck' |
| 54 | + } finally { |
| 55 | + junit '**/build/**/*.xml' |
| 56 | + archiveArtifacts artifacts: '**/build/**/*.log' |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + ) |
| 61 | +} |
| 62 | + |
| 63 | +// Publish the master branch |
| 64 | +stage('Publish') { |
| 65 | + if (env.BRANCH_NAME == "master") { |
| 66 | + node { |
| 67 | + checkout scm // re-checkout to be able to git tag |
| 68 | + unstash name: 'built' |
| 69 | + // read the version name and determine if it is a release build |
| 70 | + version = readFile('VERSION').trim() |
| 71 | + isReleaseVersion = !version.toUpperCase(Locale.ENGLISH).contains("SNAPSHOT") |
| 72 | + |
| 73 | + // Upload using the ossrh creds (upload destination logic is in build.gradle) |
| 74 | + 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')]) { |
| 75 | + sh './gradlew -Dsigning.keyId=$KEY_ID -Dsigning.password=$KEY_PASSWORD -Dsigning.secretKeyRingFile=$SIGNING_FILE -DossrhUsername=$OSSRH_USER -DossrhPassword=$OSSRH_PASSWORD upload' |
| 76 | + } |
| 77 | + |
| 78 | + // if it is a release build then do the git tagging |
| 79 | + if (isReleaseVersion) { |
| 80 | + |
| 81 | + // Read the CHANGES.md to get the tag message |
| 82 | + changes = """""" |
| 83 | + changes += readFile('CHANGES.md') |
| 84 | + tagMessage = """""" |
| 85 | + for (line in changes.readLines()) { |
| 86 | + if (!"".equals(line)) { |
| 87 | + // append the line to the tagMessage |
| 88 | + tagMessage = "${tagMessage}${line}\n" |
| 89 | + } else { |
| 90 | + break |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + // Use git to tag the release at the version |
| 95 | + try { |
| 96 | + // Awkward workaround until resolution of https://issues.jenkins-ci.org/browse/JENKINS-28335 |
| 97 | + withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'github-token', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { |
| 98 | + sh "git config user.email \"[email protected]\"" |
| 99 | + sh "git config user.name \"Jenkins CI\"" |
| 100 | + sh "git config credential.username ${env.GIT_USERNAME}" |
| 101 | + sh "git config credential.helper '!echo password=\$GIT_PASSWORD; echo'" |
| 102 | + sh "git tag -a ${version} -m '${tagMessage}'" |
| 103 | + sh "git push origin ${version}" |
| 104 | + } |
| 105 | + } finally { |
| 106 | + sh "git config --unset credential.username" |
| 107 | + sh "git config --unset credential.helper" |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments