String SLACK_NOTIFICATIONS_CHANNEL = '#graphql, #knr-alerts'

pipeline {
    agent any

    options {
        ansiColor('xterm')
        disableConcurrentBuilds()
        timestamps()
    }

    parameters {
        choice(name: 'ENVIRONMENT', choices: ['qa', 'prod'], description: 'The environment to run against.')
        stashedFile 'file.csv'
        stashedFile(name: 'contribution_ids.csv', description: 'Optional: Upload a list of contribution UUIDs to limit which contributions will get sent to kafka. One column csv file with the header `contributionUuids`')
    }

    stages {
        stage('Load Shared Libraries') {
            steps {
                library "jenkins-global-libraries@master"
            }
        }

        stage('Run script') {
            steps {
                unstash 'file.csv'
                unstash 'contribution_ids.csv'
                    yarnRun(
                        scriptNames: ["run:trigger-versioning ${params.ENVIRONMENT} file.csv contribution_ids.csv"],
                    )
            }
        }
    }

    post {
        regression {
            slackNotify channel: SLACK_NOTIFICATIONS_CHANNEL
        }
        fixed {
            slackNotify channel: SLACK_NOTIFICATIONS_CHANNEL
        }
        cleanup {
            cleanWs()
        }
    }
}
