forked from BonnierNews/logstash_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
108 lines (99 loc) · 3.48 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
def NAME
def version
pipeline {
agent { label 'jenkins-4'}
options {
buildDiscarder(
logRotator(
numToKeepStr: '5',
artifactNumToKeepStr: '5'
)
)
timestamps()
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
skipDefaultCheckout()
}
stages {
stage("Checkout") {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: 'refs/heads/'+env.BRANCH_NAME]],
extensions: [[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: '']],
userRemoteConfigs: scm.userRemoteConfigs,
])
sh "git checkout ${env.BRANCH_NAME}"
sh "git reset --hard origin/${env.BRANCH_NAME}"
}
}
stage ('Getter information') {
steps {
script {
sh 'printenv | sort'
NAME = ("logstash_exporter").toLowerCase()
TAG = sh(returnStdout: true, script: "git tag --sort version:refname | tail -1").trim()
sh "echo 'tag: ${TAG}'"
if ( env.TAG_NAME ) {
version = env.TAG_NAME.toLowerCase()
} else if ( env.BRANCH_NAME.startsWith('PR') ) {
version = "${TAG}.${env.BRANCH_NAME.replace('PR-', '')}-${env.BUILD_ID}"
} else {
version = "${TAG}-${env.BRANCH_NAME}-${env.BUILD_ID}"
}
sh "echo ${version}"
}
}
}
stage('Run Tests') {
agent {
docker {
image 'golang:1.13.0-buster'
reuseNode true
}
}
steps {
sh 'go test'
}
}
stage('Build go package') {
agent {
docker {
image 'golang:1.13.0-buster'
reuseNode true
}
}
steps {
sh "go build -o ./build/${NAME} -ldflags \"-s -X github.com/productsupcom/logstash_exporter/vendor/github.com/prometheus/common/version.Version=${version}\""
}
}
stage ('Build deb package') {
steps {
script {
sh "version=${version} nfpm pkg --target ${NAME}_${version}_all.deb"
sh "dpkg-deb -I ${NAME}_${version}_all.deb"
sh "dpkg -c ${NAME}_${version}_all.deb"
}
}
}
stage ('Publish deb package') {
when {
buildingTag()
}
steps {
sshagent (credentials: ['jenkins-ssh']) {
script {
sh "scp -o StrictHostKeyChecking=no ${NAME}_${version}_all.deb root@aptly.productsup.com:/tmp/"
sh "ssh -o StrictHostKeyChecking=no root@aptly.productsup.com \"aptly repo add stable /tmp/${NAME}_${version}_all.deb && \
aptly publish update -passphrase-file='/root/.aptly/passphrase' -batch stable s3:aptly-productsup:debian && rm /tmp/${NAME}_${version}_all.deb\""
}
}
}
}
}
post ('Cleanup') {
cleanup {
cleanWs deleteDirs: true
}
}
}