-
Notifications
You must be signed in to change notification settings - Fork 10
/
Jenkinsfile
71 lines (66 loc) · 2.22 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pipeline {
agent any
tools {
go 'go1.14'
}
parameters {
string(name: 'RECIPIENTS', defaultValue: '[email protected]', description: 'Email for the build result')
}
environment {
GO114MODULE = 'on'
CGO_ENABLED = 0
GOPATH = "${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}"
}
stages {
stage('Pre Test') {
steps {
echo 'Installing dependencies'
sh 'go version'
sh 'go get -u golang.org/x/lint/golint'
}
}
stage('Build') {
when {
anyOf { branch 'master'; branch 'staging' }
}
steps {
echo 'Compiling and building'
sh 'go build'
}
}
stage('Test') {
steps {
withEnv(["PATH+GO=${GOPATH}/bin"]){
echo 'Running vetting'
sh 'go vet .'
echo 'Running linting'
sh 'golint .'
echo 'Running test'
sh 'cd test && go test -v'
}
}
}
stage('Deploy') {
when {
branch 'master'
}
steps {
echo 'Deploy the app'
}
}
}
post {
always {
emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}",
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
to: "${params.RECIPIENTS}",
subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"
}
success {
slackSend color: '#27ae60', message: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}", channel: 'jenkins'
}
failure {
slackSend color: '#e74c3c', message: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}", channel: 'jenkins'
}
}
}