pipeline {
  // Some steps hang forever. Rather than take an agent, we are good Jenkins denizens and explicitly say when we want
  // a jenkins worker
  agent none
  options {
    timestamps()
    ansiColor('xterm')
  }

  stages {
    stage("Set up") {
      agent any
      steps {
        script {
          // Put the short git SHA in the build name so we can find a build by SHA on the UI
          currentBuild.displayName = env.GIT_COMMIT[0..6] + " #" + env.BUILD_NUMBER
        }

        // Clean the workspace, removing files created by other builds.
        sh 'git clean -ffdx'
      }
    }

    stage("Build go binaries") {
      agent {
        docker {
          image 'docker-registry.internal.justin.tv/devtools/xenial/go1.13.5:latest'
          args '-u root'
        }
      }
      steps {
        // Print some debug info
        sh 'go version'
        sh 'go env'

        // Build and test our library
        sh 'go build ./...'
        sh 'go test -v ./...'
      }
    }
  }
}
