Jenkinsfile 6.14 KB
Newer Older
Christophe Henry's avatar
Christophe Henry committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
pipeline {
    agent {
        docker {
            image "bitriseio/docker-android"
            args "-v /etc/passwd:/etc/passwd:ro -u root --privileged"
        }
    }

    environment {
        MIN_SDK_IMAGE = "system-images;android-21;default;x86_64"
        TARGET_SDK_IMAGE = "system-images;android-28;default;x86_64"
        ANDROID_HOME = "/opt/android-sdk-linux"
    }

    options {
        buildDiscarder(logRotator(numToKeepStr: "2"))
        skipStagesAfterUnstable()
        gitLabConnection('GitlabFeneas')
    }

    triggers {
Christophe Henry's avatar
Christophe Henry committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        gitlab(
            branchFilterType: 'All',
            triggerOnPush: true,
            triggerOnMergeRequest: false,
            triggerOpenMergeRequestOnPush: "never",
            triggerOnNoteRequest: true,
            noteRegex: "Jenkins please retry a build",
            skipWorkInProgressMergeRequest: false,
            ciSkip: false,
            setBuildDescription: true,
            addNoteOnMergeRequest: true,
            addCiMessage: true,
            addVoteOnMergeRequest: true,
            acceptMergeRequestOnSuccess: false,
        )
Christophe Henry's avatar
Christophe Henry committed
37 38 39 40 41
    }

    stages {
        stage("Pre") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
42
                updateGitlabCommitStatus name: "Job", state: "running"
Christophe Henry's avatar
Christophe Henry committed
43
                updateGitlabCommitStatus name: "Pre", state: "running"
Christophe Henry's avatar
Christophe Henry committed
44 45 46
                library "android-pipeline-steps"
                sh "apt-get install net-tools"
            }
Christophe Henry's avatar
Christophe Henry committed
47 48 49 50 51 52 53 54
            post {
                failure {
                    updateGitlabCommitStatus name: "Pre", state: "failed"
                }
                success {
                    updateGitlabCommitStatus name: "Pre", state: "success"
                }
            }
Christophe Henry's avatar
Christophe Henry committed
55 56 57
        }
        stage("Compile") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
58
                updateGitlabCommitStatus name: "Compile", state: "running"
Christophe Henry's avatar
Christophe Henry committed
59 60
                sh "./gradlew compileReleaseSources"
            }
Christophe Henry's avatar
Christophe Henry committed
61 62 63 64 65 66 67 68 69

            post {
                failure {
                    updateGitlabCommitStatus name: "Compile", state: "failed"
                }
                success {
                    updateGitlabCommitStatus name: "Compile", state: "success"
                }
            }
Christophe Henry's avatar
Christophe Henry committed
70
        }
71
        stage("Lint") {
Christophe Henry's avatar
Christophe Henry committed
72
            steps {
73 74
                updateGitlabCommitStatus name: "Lint", state: "running"
                sh "./gradlew spotlessApply lint"
Christophe Henry's avatar
Christophe Henry committed
75 76 77 78 79 80 81 82 83 84 85 86
                sh "./gradlew lintRelease --continue"
                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         : ""
                ])
            }
Christophe Henry's avatar
Christophe Henry committed
87 88 89

            post {
                failure {
90
                    updateGitlabCommitStatus name: "Lint", state: "failed"
Christophe Henry's avatar
Christophe Henry committed
91 92
                }
                success {
93
                    updateGitlabCommitStatus name: "Lint", state: "success"
Christophe Henry's avatar
Christophe Henry committed
94 95
                }
            }
Christophe Henry's avatar
Christophe Henry committed
96 97 98
        }
        stage("Unit tests") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
99
                updateGitlabCommitStatus name: "Unit tests", state: "running"
Christophe Henry's avatar
Christophe Henry committed
100 101 102 103 104 105 106 107 108 109 110 111
                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         : ""
                ])
            }
Christophe Henry's avatar
Christophe Henry committed
112 113 114 115 116 117 118 119 120

            post {
                failure {
                    updateGitlabCommitStatus name: "Unit tests", state: "failed"
                }
                success {
                    updateGitlabCommitStatus name: "Unit tests", state: "success"
                }
            }
Christophe Henry's avatar
Christophe Henry committed
121 122 123
        }
        stage("Instrumented tests on min SDK image") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
124
                updateGitlabCommitStatus name: "Instrumented tests on min SDK image", state: "running"
Christophe Henry's avatar
Christophe Henry committed
125 126 127 128
                withAvd(hardwareProfile: "Nexus 5X", systemImage: env.MIN_SDK_IMAGE, headless: true) {
                    sh "./gradlew clean connectedDebugAndroidTest"
                }
            }
Christophe Henry's avatar
Christophe Henry committed
129 130 131 132 133 134 135 136 137

            post {
                failure {
                    updateGitlabCommitStatus name: "Instrumented tests on min SDK image", state: "failed"
                }
                success {
                    updateGitlabCommitStatus name: "Instrumented tests on min SDK image", state: "success"
                }
            }
Christophe Henry's avatar
Christophe Henry committed
138 139 140
        }
        stage("Instrumented tests on target SDK image") {
            steps {
Christophe Henry's avatar
Christophe Henry committed
141
                updateGitlabCommitStatus name: "Instrumented tests on target SDK image", state: "running"
Christophe Henry's avatar
Christophe Henry committed
142 143 144 145
                withAvd(hardwareProfile: "Nexus 5X", systemImage: env.TARGET_SDK_IMAGE, headless: true) {
                    sh "./gradlew clean connectedDebugAndroidTest"
                }
            }
Christophe Henry's avatar
Christophe Henry committed
146 147 148 149 150 151 152 153 154

            post {
                failure {
                    updateGitlabCommitStatus name: "Instrumented tests on target SDK image", state: "failed"
                }
                success {
                    updateGitlabCommitStatus name: "Instrumented tests on target SDK image", state: "success"
                }
            }
Christophe Henry's avatar
Christophe Henry committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
        }
//        stage("Build APK") {
//            steps {
//                withAvd(hardwareProfile: "Nexus 5X", systemImage: env.MIN_SDK_IMAGE, headless: true) {
//                    sh "./gradlew assembleDebug"
//                    archiveArtifacts "**/*.apk"
//                }
//            }
//        }
    }

    post {
        always {
            sh "chown -R jenkins ${env.WORKSPACE}"
        }
Christophe Henry's avatar
Christophe Henry committed
170 171 172 173 174 175
        failure {
            updateGitlabCommitStatus name: "Job", state: "failed"
        }
        success {
            updateGitlabCommitStatus name: "Job", state: "success"
        }
Christophe Henry's avatar
Christophe Henry committed
176 177
    }
}