Jenkinsfile 5.88 KB
Newer Older
augier's avatar
augier 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 {
augier's avatar
augier 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,
        )
augier's avatar
augier committed
37 38 39 40 41
    }

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

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

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

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

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

            post {
                failure {
                    updateGitlabCommitStatus name: "Instrumented tests on target SDK image", state: "failed"
                }
                success {
                    updateGitlabCommitStatus name: "Instrumented tests on target SDK image", state: "success"
                }
            }
augier's avatar
augier committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
        }
//        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}"
        }
    }
}