// #!groovy

// def agentPod = '''
// apiVersion: v1
// kind: Pod
// spec:
//   containers:
//   - name: main
//     image: gcr.io/pingcap-public/third-party/pulumi:v2.15.3-go-v1.15.15
//     command:
//     - cat
//     tty: true
//     resources:
//       requests:
//         memory: 8Gi
//         cpu: 3
//     env:
//     - name: DOCKER_HOST
//       value: tcp://localhost:2375
//     - name: AWS_WEB_IDENTITY_TOKEN_FILE
//       value: /identity/token
//     volumeMounts:
//     - mountPath: /identity
//       name: identity
//   - name: dind
//     image: docker:18.09-dind
//     securityContext:
//       privileged: true
//   - name: auth
//     image: gcr.io/pingcap-gardener/jenkins/gcp-web-identity:20201201
//     env:
//     - name: AWS_WEB_IDENTITY_TOKEN_FILE
//       value: /identity/token
//     volumeMounts:
//     - mountPath: /identity
//       name: identity
//   restartPolicy: Never
//   volumes:
//   - emptyDir: {}
//     name: identity
// '''

// pipeline {
//     agent {
//         kubernetes {
//             yaml agentPod
//             defaultContainer "main"
//             customWorkspace "/home/jenkins/agent/workspace/go/src/github.com/tidbcloud/infra-api"
//         }
//     }

//     environment {
//         GOPATH = "/home/jenkins/agent/workspace/go"
//         GOPRIVATE = "github.com/tidbcloud,github.com/pingcap/dbaas"
//         KUBEBUILDER_CONTROLPLANE_START_TIMEOUT = "60s"
//         GITHUB_BOT = credentials("github-sre-bot")
//     }

//     stages {
//         stage('Setup') {
//             steps {
//                 sh '''
//                 # permission to get private go packages
//                 echo "machine github.com login ${GITHUB_BOT_USR} password ${GITHUB_BOT_PSW}" > ~/.netrc
//                 '''
//             }
//         }
//         stage('Build') {
//             when {
//                 buildingTag()
//             }
//             steps {
//                 sh '''
//                 make docker-build
//                 '''
//             }
//             post {
//                 unsuccessful {
//                     script {
//                         sendNotification("#dbaas-infra-ci", "FAILED")
//                     }
//                 }
//             }
//         }
//         stage('Push Prod') {
//             when {
//                 buildingTag()
//             }
//             environment {
//                 AWS_DEFAULT_REGION = "us-west-2"
//                 AWS_ROLE_ARN = credentials("dbaas-prod-aws-role")
//             }
//             steps {
//                 sh '''
//                 REGION=us-west-2 ./hack/push-ecr.sh infra-provider:latest
//                 '''
//             }
//         }
//     }
// }


// def sendNotification(String CHANNEL, String STATUS) {
//     def GIT_AUTHOR_NAME = sh(returnStdout: true, script: "git log -1 --pretty=format:'%an'").trim()
//     def GIT_COMMIT_MSG = sh(returnStdout: true, script: "git log --oneline -n 1 --pretty=%B HEAD | head -n 1").trim()
//     def slackmsg = "[<${env.RUN_DISPLAY_URL}|Build Config-Service Image>] `${STATUS}`" + "\n" +
//             "Commit: <https://github.com/tidbcloud/infra-api/commit/${env.GIT_COMMIT}|${GIT_COMMIT_MSG}>" + '\n' +
//             "Authored by: `${GIT_AUTHOR_NAME}`"
//     def COLOR = 'good'
//     if (STATUS != "SUCCESS") {
//         COLOR = 'danger'
//     }
//     slackSend channel: CHANNEL, color: COLOR, teamDomain: 'pingcap', tokenCredentialId: 'slack-pingcap-token', message: "${slackmsg}"
// }