Jenkinsfile 5.12 KB
Newer Older
augier's avatar
augier committed
1 2 3 4
pipeline {
    agent {
        docker {
            image "bitriseio/docker-android"
Christophe Henry's avatar
Christophe Henry committed
5 6
            args "-v /etc/passwd:/etc/passwd:ro " +
                "-v /home/android/android-sdk-linux/:/opt/android-sdk-linux/:rw " +
7 8
                // Disable for now, see https://stackoverflow.com/a/55590096
                // "-v /home/android/.gradle/:/root/.gradle/:rw " +
9
                "-v /home/android/freshrss_signkey.jks:/home/android/freshrss_signkey.jks:ro " +
Christophe Henry's avatar
Christophe Henry committed
10
                "-u root --privileged"
augier's avatar
augier committed
11 12 13 14
        }
    }

    environment {
Christophe Henry's avatar
Christophe Henry committed
15
        MIN_SDK_VERSION = 23
16
        MAX_SDK_VERSION = 28
Christophe Henry's avatar
Christophe Henry committed
17 18
        MIN_SDK_IMAGE = "system-images;android-$MIN_SDK_VERSION;default;x86_64".toString()
        MAX_SDK_IMAGE = "system-images;android-$MAX_SDK_VERSION;default;x86_64".toString()
augier's avatar
augier committed
19
        ANDROID_HOME = "/opt/android-sdk-linux"
20 21
        SIGN_KEY_PATH = "/home/android/freshrss_signkey.jks"
        SIGN_KEY_CREDENTIALS = credentials "freshrss-signkey"
augier's avatar
augier committed
22 23 24 25 26 27
    }

    options {
        buildDiscarder(logRotator(numToKeepStr: "2"))
        skipStagesAfterUnstable()
        gitLabConnection('GitlabFeneas')
28
        gitlabBuilds(builds: getBuildSteps(env.BRANCH_NAME))
Christophe Henry's avatar
Christophe Henry committed
29 30 31 32
        disableConcurrentBuilds()
        newContainerPerStage()
        timestamps()
        timeout(time: 30, unit: 'MINUTES')
augier's avatar
augier committed
33 34 35
    }

    triggers {
augier's avatar
augier committed
36 37 38 39 40 41 42 43
        gitlab(
            branchFilterType: 'All',
            triggerOnPush: true,
            triggerOnMergeRequest: false,
            triggerOpenMergeRequestOnPush: "never",
            triggerOnNoteRequest: true,
            noteRegex: "Jenkins please retry a build",
            skipWorkInProgressMergeRequest: false,
Christophe Henry's avatar
Christophe Henry committed
44
            ciSkip: true,
augier's avatar
augier committed
45 46 47 48 49
            setBuildDescription: true,
            addNoteOnMergeRequest: true,
            addCiMessage: true,
            addVoteOnMergeRequest: true,
            acceptMergeRequestOnSuccess: false,
Christophe Henry's avatar
Christophe Henry committed
50
            cancelPendingBuildsOnUpdate: true
augier's avatar
augier committed
51
        )
augier's avatar
augier committed
52 53
    }

Christophe Henry's avatar
Christophe Henry committed
54 55 56 57
    libraries {
        lib("android-pipeline-steps")
    }

augier's avatar
augier committed
58
    stages {
59
        stage("Lint") {
augier's avatar
augier committed
60
            steps {
Christophe Henry's avatar
Christophe Henry committed
61 62 63 64 65 66 67 68 69 70 71 72
                gitlabCommitStatus("Lint") {
                    sh "./gradlew spotlessCheck lint"
                    androidLint pattern: "**/lint-results-*.xml"
                    publishHTML([
                        allowMissing         : false,
                        alwaysLinkToLastBuild: true,
                        keepAll              : false,
                        reportDir            : "$WORKSPACE/app/build/reports/",
                        reportFiles          : "lint-results-release.html",
                        reportName           : "HTML Report",
                        reportTitles         : ""
                    ])
augier's avatar
augier committed
73 74
                }
            }
augier's avatar
augier committed
75
        }
Christophe Henry's avatar
Christophe Henry committed
76

augier's avatar
augier committed
77 78
        stage("Unit tests") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
79
                gitlabCommitStatus("Unit tests") {
Christophe Henry's avatar
Christophe Henry committed
80
                    sh "./gradlew testDebugUnitTest"
Christophe Henry's avatar
Christophe Henry committed
81 82 83 84 85 86 87 88 89 90
                    junit "**/test-results/**/*.xml"
                    publishHTML([
                        allowMissing         : false,
                        alwaysLinkToLastBuild: true,
                        keepAll              : false,
                        reportDir            : "$WORKSPACE/app/build/reports/tests/testReleaseUnitTest",
                        reportFiles          : "index.html",
                        reportName           : "Junit test report",
                        reportTitles         : ""
                    ])
augier's avatar
augier committed
91 92
                }
            }
augier's avatar
augier committed
93
        }
augier's avatar
augier committed
94

95 96 97 98 99
        stage("on min SDK level") {
            steps {
                gitlabCommitStatus("Instrumented tests on min SDK image") {
                    withAvd(hardwareProfile: "Nexus 5X", systemImage: env.MIN_SDK_IMAGE, headless: true) {
                        sh "./gradlew clean connectedCheck"
100
                    }
augier's avatar
augier committed
101
                }
102 103
            }
        }
augier's avatar
augier committed
104

105 106 107 108 109
        stage("on max SDK level") {
            steps {
                gitlabCommitStatus("Instrumented tests on max SDK image") {
                    withAvd(hardwareProfile: "Nexus 5X", systemImage: env.MAX_SDK_IMAGE, headless: true) {
                        sh "./gradlew clean connectedCheck"
110
                    }
augier's avatar
augier committed
111 112
                }
            }
augier's avatar
augier committed
113
        }
114

115 116 117
        stage("Build APK") {
            steps {
                gitlabCommitStatus("Build APK") {
Christophe Henry's avatar
~  
Christophe Henry committed
118
                    sh("""./gradlew clean assembleJenkins \
119 120 121 122 123 124 125 126
                            -Pandroid.injected.signing.store.file=${env.SIGN_KEY_PATH} \
                            -Pandroid.injected.signing.store.password=${env.SIGN_KEY_CREDENTIALS_PSW} \
                            -Pandroid.injected.signing.key.alias=${env.SIGN_KEY_CREDENTIALS_USR} \
                            -Pandroid.injected.signing.key.password=${env.SIGN_KEY_CREDENTIALS_PSW}
                        """)
                    archiveArtifacts artifacts: "**/*.apk", fingerprint: true
                }
            }
127 128

            when { branch "develop" }
129
        }
augier's avatar
augier committed
130
    }
131 132 133 134 135 136 137
}

def getBuildSteps(String branch) {
    def buildSteps = [
        "Lint",
        "Unit tests",
        "Instrumented tests on min SDK image",
Christophe Henry's avatar
~  
Christophe Henry committed
138
        "Instrumented tests on max SDK image",
139
    ]
140
    if (branch == "develop") return buildSteps + ["Build APK"]
141
    return buildSteps
augier's avatar
augier committed
142
}