/* groovylint-disable DuplicateStringLiteral, LineLength */
pipeline {
    agent any
    parameters {
        string(name: 'NEW_LTS_CODENAME', description: 'The name of the next LTS (ex: orion)', trim: true)
        booleanParam(name: 'IS_CURRENT_LTS_RELEASED', description: 'Defined if we set current lts as released')
    }
    stages {
        stage('Clone repository') {
            steps {
                git url: 'git@gitlab.com:xivo.solutions/xivo-ci.git', branch: 'master', credentialsId: 'Gitlab-avencall-private-repo-read'
            }
        }
        stage('Update xivo-version.sh') {
            steps {
                dir('bin') {
                    sh "./update-xivo-version.sh ${params.IS_CURRENT_LTS_RELEASED} ${params.NEW_LTS_CODENAME}"
                }
            }
        }
        stage('Build and update xivo-ci on jenkins') {
            steps {
                build(
                    job: 'xivo-ci',
                    parameters: [
                        string(name: 'BRANCH_OR_TAG', value: 'master'),
                        string(name: 'BUILD_TYPE', value: 'dev'),
                    ]
                )
                script {
                    sh 'sudo apt update && sudo apt install -y xivo-ci'
                }
            }
        }
    }
}
