Jenkinsfile 5.37 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
                "-v /home/android/.gradle/:/root/.gradle/:rw " +
8
                "-v /home/android/freshrss_signkey.jks:/home/android/freshrss_signkey.jks:ro " +
Christophe Henry's avatar
Christophe Henry committed
9
                "-u root --privileged"
augier's avatar
augier committed
10 11 12 13
        }
    }

    environment {
Christophe Henry's avatar
Christophe Henry committed
14
        MIN_SDK_VERSION = 23
15
        MAX_SDK_VERSION = 28
Christophe Henry's avatar
Christophe Henry committed
16 17
        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
18
        ANDROID_HOME = "/opt/android-sdk-linux"
19 20
        SIGN_KEY_PATH = "/home/android/freshrss_signkey.jks"
        SIGN_KEY_CREDENTIALS = credentials "freshrss-signkey"
augier's avatar
augier committed
21 22 23 24 25 26
    }

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

    triggers {
augier's avatar
augier committed
35 36 37 38 39 40 41 42
        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
43
            ciSkip: true,
augier's avatar
augier committed
44 45 46 47 48
            setBuildDescription: true,
            addNoteOnMergeRequest: true,
            addCiMessage: true,
            addVoteOnMergeRequest: true,
            acceptMergeRequestOnSuccess: false,
Christophe Henry's avatar
Christophe Henry committed
49
            cancelPendingBuildsOnUpdate: true
augier's avatar
augier committed
50
        )
augier's avatar
augier committed
51 52
    }

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

augier's avatar
augier committed
57
    stages {
augier's avatar
augier committed
58
        stage("Lint") {
augier's avatar
augier committed
59
            steps {
Christophe Henry's avatar
Christophe Henry committed
60 61 62 63 64 65 66 67 68 69 70 71
                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
72 73
                }
            }
augier's avatar
augier committed
74
        }
Christophe Henry's avatar
Christophe Henry committed
75

augier's avatar
augier committed
76 77
        stage("Unit tests") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
78 79 80 81 82 83 84 85 86 87 88 89
                gitlabCommitStatus("Unit tests") {
                    sh "./gradlew testReleaseUnitTest --info"
                    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
90 91
                }
            }
augier's avatar
augier committed
92
        }
augier's avatar
augier committed
93

Christophe Henry's avatar
~  
Christophe Henry committed
94 95 96 97 98 99 100 101 102
        stage("Run instrumented tests") {
            parallel {
                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"
                            }
                        }
103
                    }
augier's avatar
augier committed
104
                }
augier's avatar
augier committed
105

Christophe Henry's avatar
~  
Christophe Henry committed
106 107 108 109 110 111 112
                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"
                            }
                        }
113
                    }
augier's avatar
augier committed
114 115
                }
            }
augier's avatar
augier committed
116
        }
117

118 119 120
        stage("Build APK") {
            steps {
                gitlabCommitStatus("Build APK") {
Christophe Henry's avatar
~  
Christophe Henry committed
121
                    sh("""./gradlew clean assembleJenkins \
122 123 124 125 126 127 128 129
                            -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
                }
            }
130 131

            when { branch "develop" }
132
        }
augier's avatar
augier committed
133
    }
Christophe Henry's avatar
Christophe Henry committed
134 135 136 137 138 139

    post {
        always {
            sh "chown jenkins: ${env.WORKSPACE}"
        }
    }
140 141 142 143 144 145 146
}

def getBuildSteps(String branch) {
    def buildSteps = [
        "Lint",
        "Unit tests",
        "Instrumented tests on min SDK image",
Christophe Henry's avatar
~  
Christophe Henry committed
147
        "Instrumented tests on max SDK image",
148 149 150
    ]
    if(branch == "develop") return buildSteps + ["Build APK"]
    return buildSteps
augier's avatar
augier committed
151
}