#!/usr/bin/env groovy

library 'jenkins-shared-library@grafana-fixes' // https://git.xarth.tv/chat/jenkins-shared-library

def dashboardID = 1440
def serviceName = 'testapp'

pipeline {
  agent any
  options {
    // Add timestamps before stdout/stderr in jenkins logs
    timestamps()
    // Let the jenkins logs show console command colors
    ansiColor('xterm')
    // Don't bother running builds if the pushes happen one right after the other
    quietPeriod(30)
  }
  stages {
    stage("build") {
      agent any

      environment {
        SLACK_OAUTH_TOKEN = credentials('communications_slack_deploy_oauth_token')
      }
      stages {
        stage("Stage 1") {
          steps {
            milestone(100)
            sh "printenv"
            sh "echo hello"
            postGrafanaDeployAnnotation(serviceName: serviceName, dashboardID: dashboardID, envName: "Staging", status: "Success")
            postGrafanaDeployAnnotation(serviceName: serviceName, dashboardID: dashboardID, envName: "Canary", status: "Success")
            postGrafanaDeployAnnotation(serviceName: serviceName, dashboardID: dashboardID, envName: "Production", status: "Success")
            postGrafanaDeployAnnotation(serviceName: serviceName, dashboardID: dashboardID, envName: "Production", status: "Failure")
          }
        }
      }
    }
  }
}
