forked from Blazemeter/taurus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
94 lines (93 loc) · 3.4 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
@Library("jenkins_library") _
pipeline {
agent {
dockerfile {
label 'google'
filename 'tests/ci/Dockerfile'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
options {
timestamps()
}
stages {
stage('Checkout') {
steps {
script {
initJenkinsGlobal()
tagName = sh(returnStdout: true, script: "git tag --points-at HEAD").trim()
isRelease = !tagName.isEmpty()
IMAGE_TAG = env.JOB_NAME + "." + env.BUILD_NUMBER
IMAGE_TAG = IMAGE_TAG.toLowerCase()
imageName = "blazemeter/taurus"
date = sh(returnStdout: true, script: "echo \$(date '+%Y-%m-%d')").trim()
commitSha = GIT_COMMIT.take(8)
imageTag = "${imageName}:master-${commitSha}-${date}"
extraImageTag = isRelease ? "${imageName}:${tagName} -t ${imageTag} -t ${imageName}:latest" : "${imageName}:unstable -t ${imageTag}"
sh "./build-info.sh ${isRelease}"
}
}
}
stage("Create artifacts") {
steps {
script {
sh "./build-artifacts.sh"
}
archiveArtifacts artifacts: 'dist/*.whl', fingerprint: true
}
}
stage("Docker Image Build") {
steps {
script {
sh "docker build --no-cache -t ${JOB_NAME} -t ${extraImageTag} ."
}
}
}
stage("Integration Tests") {
steps {
sh """
docker run -v `pwd`:/bzt-configs -v `pwd`/integr-artifacts:/tmp/artifacts ${JOB_NAME} -sequential examples/all-executors.yml
"""
}
}
stage("Deploy an artifact to PyPi") {
when { expression { isRelease } }
steps {
withCredentials([usernamePassword(credentialsId: 'bzt-pypi', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "python3 -m twine upload -u ${USERNAME} -p ${PASSWORD} dist/*"
}
}
}
stage("Docker Image Push") {
steps {
withDockerRegistry([ credentialsId: "dockerhub-access", url: "" ]) {
sh "docker image push --all-tags ${imageName}"
}
}
}
stage("Deploy site") {
steps {
script {
PROJECT_ID = "blazemeter-taurus-website-prod"
withCredentials([file(credentialsId: PROJECT_ID, variable: 'CRED_JSON')]) {
sh """
gcloud auth activate-service-account --key-file ${CRED_JSON}
gcloud config set project ${PROJECT_ID}
gcloud config set compute/zone us-central1-a
"""
}
sh """
export PROJECT_ID=${PROJECT_ID}
./site/deploy-site.sh ${isRelease}
"""
}
}
}
}
post {
always {
smartSlackNotification(channel: "taurus-dev", buildStatus:currentBuild.result ?: 'SUCCESS')
cleanWs()
}
}
}