forked from Percona-Lab/pmm-submodules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
168 lines (162 loc) · 6.96 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
library changelog: false, identifier: 'lib@master', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/Percona-Lab/jenkins-pipelines.git'
]) _
pipeline {
agent {
label 'large-amazon'
}
stages {
stage('Prepare') {
steps {
sh '''
sudo rm -rf results tmp || :
git reset --hard
git clean -fdx
git submodule foreach --recursive git reset --hard
git submodule foreach --recursive git clean -fdx
'''
installDocker()
slackSend channel: '#pmm-ci', color: '#FFFF00', message: "[${JOB_NAME}]: build started - ${BUILD_URL}"
}
}
stage('Build client source') {
steps {
sh '''
sg docker -c "
env
export pmm_version=$(cat VERSION)
./build/bin/build-client-source
"
'''
}
}
stage('Build client binary') {
steps {
sh '''
sg docker -c "
export pmm_version=$(cat VERSION)
./build/bin/build-client-binary
"
'''
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AMI/OVF', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh '''
aws s3 cp \
--acl public-read \
results/tarball/pmm-client-*.tar.gz \
s3://pmm-build-cache/pmm-client/pmm-client-${BRANCH_NAME}-${GIT_COMMIT:0:7}.tar.gz
'''
}
}
}
stage('Build client source rpm') {
steps {
sh 'sg docker -c "./build/bin/build-client-srpm centos:6"'
}
}
stage('Build client binary rpm') {
steps {
sh '''
sg docker -c "
./build/bin/build-client-rpm centos:7
mkdir -p tmp/pmm-server/RPMS/
cp results/rpm/pmm-client-*.rpm tmp/pmm-server/RPMS/
"
'''
}
}
stage('Build client docker') {
steps {
withCredentials([usernamePassword(credentialsId: 'hub.docker.com', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh """
sg docker -c "
docker login -u "${USER}" -p "${PASS}"
"
"""
}
sh '''
sg docker -c "
export PUSH_DOCKER=1
export DOCKER_CLIENT_TAG=perconalab/pmm-client-fb:${BRANCH_NAME}-${GIT_COMMIT:0:7}
./build/bin/build-client-docker
"
'''
stash includes: 'results/docker/CLIENT_TAG', name: 'CLIENT_IMAGE'
archiveArtifacts 'results/docker/CLIENT_TAG'
}
}
stage('Build server packages') {
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AMI/OVF', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh '''
sg docker -c "
export PATH=$PATH:$(pwd -P)/build/bin
# 1st-party
build-server-rpm percona-dashboards grafana-dashboards
build-server-rpm pmm-manage
build-server-rpm pmm-managed
build-server-rpm percona-qan-api qan-api
build-server-rpm percona-qan-app qan-app
build-server-rpm pmm-server
build-server-rpm pmm-update
# 3rd-party
build-server-rpm consul
build-server-rpm orchestrator
build-server-rpm rds_exporter
build-server-rpm prometheus
build-server-rpm prometheus1
build-server-rpm grafana
"
'''
}
}
}
stage('Build server docker') {
steps {
withCredentials([usernamePassword(credentialsId: 'hub.docker.com', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh """
sg docker -c "
docker login -u "${USER}" -p "${PASS}"
"
"""
}
sh '''
sg docker -c "
export PUSH_DOCKER=1
export DOCKER_TAG=perconalab/pmm-server-fb:${BRANCH_NAME}-${GIT_COMMIT:0:7}
./build/bin/build-server-docker
"
'''
stash includes: 'results/docker/TAG', name: 'IMAGE'
archiveArtifacts 'results/docker/TAG'
}
}
}
post {
always {
script {
if (currentBuild.result == null || currentBuild.result == 'SUCCESS') {
unstash 'IMAGE'
def IMAGE = sh(returnStdout: true, script: "cat results/docker/TAG").trim()
def CLIENT_IMAGE = sh(returnStdout: true, script: "cat results/docker/CLIENT_TAG").trim()
if (env.CHANGE_URL) {
withCredentials([string(credentialsId: 'GITHUB_API_TOKEN', variable: 'GITHUB_API_TOKEN')]) {
sh """
set -o xtrace
curl -v -X POST \
-H "Authorization: token ${GITHUB_API_TOKEN}" \
-d "{\\"body\\":\\"server docker - ${IMAGE}\\nclient docker - ${CLIENT_IMAGE}\\nclient - https://s3.us-east-2.amazonaws.com/pmm-build-cache/pmm-client/pmm-client-${BRANCH_NAME}-\${GIT_COMMIT:0:7}.tar.gz\\"}" \
"https://api.github.com/repos/\$(echo $CHANGE_URL | cut -d '/' -f 4-5)/issues/${CHANGE_ID}/comments"
"""
}
}
slackSend channel: '#pmm-ci', color: '#00FF00', message: "[${JOB_NAME}]: build finished - ${IMAGE}"
} else {
slackSend channel: '#pmm-ci', color: '#FF0000', message: "[${JOB_NAME}]: build ${currentBuild.result}"
}
}
sh 'sudo make clean'
deleteDir()
}
}
}