Sample Jenkinsfile for Golang app

Prerequisites - plugins installed:

  1. Docker
  2. Docker Pipeline
  3. Go Plugin
  4. Pipeline
Jenkinsfile code:
pipeline {
    agent {
        label {
            label 'master'
            customWorkspace "${JENKINS_HOME}/${BUILD_NUMBER}/"
        }
    }
    environment {
        Go111MODULE='on'
    }
    stages {
    stage('Clone') {
        steps {
            git 'https://github.com/kodekloudhub/go-webapp-sample.git'
        }
    }
    stage('Test') {
        steps {
            sh 'go test ./..'
        }
    }
    stage('Build') {
        steps {
            script {
                app = docker.build("adminturneddevops/go-webapp-sample")
            }
        }
    }
    stage('Run') {
        steps {
            sh "docker run -p 8090:8000 -d adminturneddevops/go-webapp-sample"
        }
    }
    }
}