Skip to content

Commit

Permalink
Use different Jenkinsfiles for different build types
Browse files Browse the repository at this point in the history
  • Loading branch information
kiall committed Dec 24, 2016
1 parent b8cdad2 commit 234f086
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ captures/

# Keystore files
*.jks

# Editor Save Files
.*.swp
27 changes: 8 additions & 19 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env groovy

load 'Jenkinsfile.groovy'

/* Only keep the 10 most recent builds. */
def projectProperties = [
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '5']],
Expand All @@ -15,7 +17,6 @@ node ('android-slave'){
stage('Preparation') {
step([$class: 'WsCleanup'])
checkout scm
sh 'env > env-dump'
}
stage('Assemble') {
withCredentials([
Expand All @@ -26,28 +27,16 @@ node ('android-slave'){
writeFile file: 'keystore.properties', text: "storeFile=$ANDROID_KEYSTORE\nstorePassword=$ANDROID_KEYSTORE_PASSWORD\nkeyAlias=Kiall Mac Innes\nkeyPassword=$ANDROID_KEYSTORE_PASSWORD\n"
writeFile file: 'acra.properties', text: "report_uri=$ACRA_REPORT_URI\n"

sh './gradlew assemble'
assemble()
}
}
stage('Archive APK') {
archiveArtifacts artifacts: 'app/build/outputs/apk/*.apk', fingerprint: true
stash includes: 'app/build/outputs/apk/*.apk', name: 'built-apk'
}
stage('Lint') {
sh './gradlew lint'
androidLint canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: '**/lint-results*.xml', unHealthy: ''
lint()
}
stage('Archive APK') {
archive()
}
stage('Publish') {
def lastTag = sh(returnStdout: true, script: "git describe --tags --abbrev=0").trim()
def changeLog = sh(returnStdout: true, script: "git log $lastTag..HEAD --oneline | grep -v 'Merge pull request' | cut -d' ' -f2- | sed -e 's/^/* /'").trim()

androidApkUpload(
apkFilesPattern: 'app/build/outputs/apk/ie.macinnes.tvheadend_*-release.apk',
googleCredentialsId: 'android-tvheadend',
trackName: 'alpha',
recentChangeList: [
[language: 'en-GB', text: changeLog],
],
)
publishApkToStore('alpha')
}
}
26 changes: 26 additions & 0 deletions Jenkinsfile.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def assemble() {
sh './gradlew assemble'
}

def archive() {
archiveArtifacts artifacts: 'app/build/outputs/apk/*.apk', fingerprint: true
stash includes: 'app/build/outputs/apk/*.apk', name: 'built-apk'
}

def lint() {
sh './gradlew lint'
androidLint canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: '**/lint-results*.xml', unHealthy: ''
}

def publishApkToStore(trackName)
def changeLog = sh(returnStdout: true, script: "./tools/generate-changelog").trim()

androidApkUpload(
apkFilesPattern: 'app/build/outputs/apk/ie.macinnes.tvheadend_*-release.apk',
googleCredentialsId: 'android-tvheadend',
trackName: $trackName,
recentChangeList: [
[language: 'en-GB', text: changeLog],
],
)
}
42 changes: 42 additions & 0 deletions Jenkinsfile.tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env groovy

load 'Jenkinsfile.groovy'

/* Only keep the 10 most recent builds. */
def projectProperties = [
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '5']],
[$class: 'PipelineTriggersJobProperty', triggers: [
[$class: 'GitHubPushTrigger']
]],
[$class: 'DisableConcurrentBuildsJobProperty'],
]

properties(projectProperties)

node ('android-slave'){
stage('Preparation') {
step([$class: 'WsCleanup'])
checkout scm
}
stage('Assemble') {
withCredentials([
[$class: 'FileBinding', credentialsId: 'android-keystore-tvheadend', variable: 'ANDROID_KEYSTORE'],
[$class: 'StringBinding', credentialsId: 'android-keystore-tvheadend-password', variable: 'ANDROID_KEYSTORE_PASSWORD'],
[$class: 'StringBinding', credentialsId: 'acra-report-uri-tvheadend', variable: 'ACRA_REPORT_URI'],
]) {
writeFile file: 'keystore.properties', text: "storeFile=$ANDROID_KEYSTORE\nstorePassword=$ANDROID_KEYSTORE_PASSWORD\nkeyAlias=Kiall Mac Innes\nkeyPassword=$ANDROID_KEYSTORE_PASSWORD\n"
writeFile file: 'acra.properties', text: "report_uri=$ACRA_REPORT_URI\n"

assemble()
}
}
stage('Lint') {
lint()
}
stage('Archive APK') {
archive()
}
stage('Publish') {
publishApkToStore('beta')
}
}
14 changes: 14 additions & 0 deletions tools/generate-changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

git describe --exact-match HEAD &> /dev/null
if [ "$?" == "0" ]; then
THIS_TAG=$(git describe --tags --abbrev=0)
LAST_TAG=$(git describe --tags --abbrev=0 ${THIS_TAG}^)

git log $LAST_TAG...$THIS_TAG --oneline | grep -v 'Merge pull request' | cut -d' ' -f2- | sed -e 's/^/* /'

else
LAST_TAG=$(git describe --tags --abbrev=0)

git log $LAST_TAG...HEAD --oneline | grep -v 'Merge pull request' | cut -d' ' -f2- | sed -e 's/^/* /'
fi

0 comments on commit 234f086

Please sign in to comment.