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

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

    options {
        buildDiscarder(logRotator(numToKeepStr: "2"))
        skipStagesAfterUnstable()
        gitLabConnection('GitlabFeneas')
Christophe Henry's avatar
Christophe Henry committed
26
        gitlabBuilds(builds: [
27 28 29 30 31 32
            "Compile",
            "Lint",
            "Unit tests",
            "Instrumented tests on min SDK image",
            "Instrumented tests on max SDK image",
            "Build APK"
Christophe Henry's avatar
Christophe Henry committed
33 34 35 36 37
        ])
        disableConcurrentBuilds()
        newContainerPerStage()
        timestamps()
        timeout(time: 30, unit: 'MINUTES')
augier's avatar
augier committed
38 39 40
    }

    triggers {
augier's avatar
augier committed
41 42 43 44 45 46 47 48
        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
49
            ciSkip: true,
augier's avatar
augier committed
50 51 52 53 54
            setBuildDescription: true,
            addNoteOnMergeRequest: true,
            addCiMessage: true,
            addVoteOnMergeRequest: true,
            acceptMergeRequestOnSuccess: false,
Christophe Henry's avatar
Christophe Henry committed
55
            cancelPendingBuildsOnUpdate: true
augier's avatar
augier committed
56
        )
augier's avatar
augier committed
57 58
    }

Christophe Henry's avatar
Christophe Henry committed
59 60 61 62
    libraries {
        lib("android-pipeline-steps")
    }

augier's avatar
augier committed
63 64 65
    stages {
        stage("Compile") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
66 67
                gitlabCommitStatus("Compile") {
                    sh "./gradlew compileReleaseSources"
augier's avatar
augier committed
68 69
                }
            }
augier's avatar
augier committed
70
        }
Christophe Henry's avatar
Christophe Henry committed
71

augier's avatar
augier committed
72
        stage("Lint") {
augier's avatar
augier committed
73
            steps {
Christophe Henry's avatar
Christophe Henry committed
74 75 76 77 78 79 80 81 82 83 84 85
                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
86 87
                }
            }
augier's avatar
augier committed
88
        }
Christophe Henry's avatar
Christophe Henry committed
89

augier's avatar
augier committed
90 91
        stage("Unit tests") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
92 93 94 95 96 97 98 99 100 101 102 103
                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
104 105
                }
            }
augier's avatar
augier committed
106
        }
augier's avatar
augier committed
107

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

Christophe Henry's avatar
Christophe Henry committed
118 119 120 121 122
        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"
123
                    }
augier's avatar
augier committed
124 125
                }
            }
augier's avatar
augier committed
126
        }
127

128 129 130 131 132 133 134 135 136 137 138 139 140
        stage("Build APK") {
            steps {
                gitlabCommitStatus("Build APK") {
                    sh("""./gradlew clean assembleRelease \
                            -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
                }
            }
        }
augier's avatar
augier committed
141
    }
Christophe Henry's avatar
Christophe Henry committed
142 143 144 145 146 147

    post {
        always {
            sh "chown jenkins: ${env.WORKSPACE}"
        }
    }
augier's avatar
augier committed
148
}