String GITHUB_REPOSITORY = 'songwhip-images'
String SLACK_CHANNEL = '#songwhip-alerts-dev'

pipeline {
    agent any

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

    parameters {
        string(name: 'SHARED_LIBRARIES_VERSION', defaultValue: 'master', description: 'The version of the Jenkins shared libraries to use. Can be a branch, tag, Git revision or PR ref (e.g. pull/PR_NUMBER/merge).')
    }

    stages {
        stage('Load Shared Libraries') {
            steps {
                library "jenkins-global-libraries@${params.SHARED_LIBRARIES_VERSION}"
            }
        }
        stage('Validate Software Catalog Definition') {
            steps {
                datadogSoftwareCatalogValidate()
            }
            post {
                failure {
                    slackNotify channel: SLACK_CHANNEL, message: "Datadog Software catalog validation FAILED for ${GITHUB_REPOSITORY}. Please check the pipeline logs."
                }
            }
        }
        stage('Publish Software Catalog') {
            when {
                allOf {
                    branch 'master'
                }
            }
            steps {
                datadogSoftwareCatalogPublish()
            }
        }
    }
    post {
        cleanup {
            cleanWs()
        }
    }
}
