pipeline {
    agent any
    parameters {
        string(
            name: 'GIT_COMMIT',
            defaultValue: '',
            description: 'Git commit')
    }
    environment {
        shared = null
    }
    stages {
        stage('Initialize') {
            steps {
                script {
                    checkout([
                        $class: 'GitSCM',
                        branches: [[name: params.GIT_COMMIT]],
                        doGenerateSubmoduleConfigurations: false,
                        extensions: [],
                        submoduleCfg: [],
                        userRemoteConfigs: [[
                            credentialsId: '577cbc72-7d9e-4eba-924c-ecbbe6de9805',
                            url: 'git@github.com:theorchard/orchardgo.git'
                        ]]
                    ])
                    shared = load './jenkins/shared.groovy'
                    library identifier: shared.library(), changelog: false
                    shared.initGitSha(params.GIT_COMMIT)
                    shared.notifySlackStarted()
                }
            }
        }
        stage('JS') {
            steps {
                script {
                    shared.runJobWithRetry('mobile-pipeline', [
                        shared.gitCommit()
                    ])
                }
            }
        }
        stage('Native') {
            steps {
                script {
                    shared.runJobWithRetry('mobile-binaries-prod', [
                        shared.gitCommit()
                    ])
                }
            }
        }
    }
    post {
        always {
            script {
                if (currentBuild.result == null) {
                    currentBuild.result = 'ABORTED'
                }
            }
        }
        success {
            script {
                shared.notifySlackFinished()
            }
        }
        failure {
            script {
                currentBuild.result = 'FAILURE'
                shared.notifySlackFinished()
            }
        }
        aborted {
            script {
                shared.notifySlackFinished()
            }
        }
    }
}
