
List<String> services = [
  "Docker/datadog-pg-monitoring",
  "Lambda/cross_account_secret_sync",
  "Lambda/secrets_rotator",
  "Lambda/ses_complaints_hard_bounces_notifications",
  "Lambda/logs_forwarder",
  "Lambda/aws-users-key-watchdog"
]

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 or Git revision.'
    )
  }

  stages {
    stage('Load Shared Libraries') {
      steps {
        library "jenkins-global-libraries@${params.SHARED_LIBRARIES_VERSION}"
      }
    }
    stage('Validate Software Catalog Files') {
      steps {
        script {
          services.each {service ->
            datadogSoftwareCatalogValidate(
              servicePath: service,
            )
          }
        }
      }
    }
    stage('Publish Software Catalog Definition') {
      steps{
        script {
          services.each {service ->
            datadogSoftwareCatalogPublish(
              servicePath: service,
              fetchAdditionalMetadata: false,
            )
          }
        }
      }
    }
  }
}
