Skip to content

Commit 559eaef

Browse files
authored
CI-15480 Create jenkins CI pipeline (#108)
1 parent f12f35d commit 559eaef

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

.jenkins/Jenkinsfile

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Load Jenkins shared library
2+
jenkinsBranch = 'master'
3+
sharedLib = library("shared-lib@${jenkinsBranch}")
4+
5+
def siftPythonWorkflow = sharedLib.com.sift.ci.SiftPythonWorkflow.new()
6+
def ciUtil = sharedLib.com.sift.ci.CIUtil.new()
7+
def stackdriver = sharedLib.com.sift.ci.StackDriverMetrics.new()
8+
9+
// Default GitHub status context for automatically triggered builds
10+
def defaultStatusContext = 'Jenkins:auto'
11+
12+
// Pod template file for Jenkins agent pod
13+
// Pod template yaml file is defined in https://github.com/SiftScience/jenkins/tree/master/resources/jenkins-k8s-pod-templates
14+
def python2PodTemplateFile = 'python-2-7-pod-template.yaml'
15+
def python3PodTemplateFile = 'python-3-10-pod-template.yaml'
16+
def python2PodLabel = "python2-${BUILD_TAG}"
17+
def python3PodLabel = "python3-${BUILD_TAG}"
18+
19+
20+
// GitHub repo name
21+
def repoName = 'sift-python'
22+
23+
pipeline {
24+
agent none
25+
options {
26+
timestamps()
27+
skipDefaultCheckout()
28+
disableConcurrentBuilds()
29+
disableRestartFromStage()
30+
parallelsAlwaysFailFast()
31+
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '')
32+
}
33+
environment {
34+
GIT_BRANCH = "${env.CHANGE_BRANCH != null? env.CHANGE_BRANCH : env.BRANCH_NAME}"
35+
}
36+
stages {
37+
stage('Initialize') {
38+
steps {
39+
script {
40+
statusContext = defaultStatusContext
41+
// Get the commit sha for the build
42+
commitSha = ciUtil.commitHashForBuild()
43+
ciUtil.updateGithubCommitStatus(repoName, statusContext, 'Started', 'pending', commitSha)
44+
}
45+
}
46+
}
47+
stage ('Build and Test Workflows') {
48+
steps {
49+
script {
50+
def workflows = [:]
51+
def stage1 = 'Run Integration Tests - python3'
52+
workflows[stage1] = {
53+
stage(stage1) {
54+
if (env.GIT_BRANCH.equals('master')) {
55+
ciUtil.updateGithubCommitStatus(repoName, stage1, 'Started', 'pending', commitSha)
56+
try {
57+
siftPythonWorkflow.runSiftPythonIntegration(python3PodTemplateFile, python3PodLabel)
58+
ciUtil.updateGithubCommitStatus(repoName, stage1, 'SUCCESS', 'success', commitSha)
59+
} catch (Exception e) {
60+
ciUtil.updateGithubCommitStatus(repoName, stage1, 'FAILURE', 'failure', commitSha)
61+
print("${stage1} failed")
62+
throw e
63+
}
64+
}
65+
}
66+
}
67+
def stage2 = 'Build and Test - python2'
68+
workflows[stage2] = {
69+
stage(stage2) {
70+
ciUtil.updateGithubCommitStatus(repoName, stage2, 'Started', 'pending', commitSha)
71+
try {
72+
siftPythonWorkflow.runSiftPythonBuildAndTest(python2PodTemplateFile, python2PodLabel, '3.0.5', '2.27.1')
73+
ciUtil.updateGithubCommitStatus(repoName, stage2, 'SUCCESS', 'success', commitSha)
74+
} catch (Exception e) {
75+
ciUtil.updateGithubCommitStatus(repoName, stage2, 'FAILURE', 'failure', commitSha)
76+
print("${stage2} failed")
77+
throw e
78+
}
79+
}
80+
}
81+
def stage3 = 'Build and Test - python3'
82+
workflows[stage3] = {
83+
stage(stage3) {
84+
ciUtil.updateGithubCommitStatus(repoName, stage3, 'Started', 'pending', commitSha)
85+
try {
86+
siftPythonWorkflow.runSiftPythonBuildAndTest(python3PodTemplateFile, python3PodLabel, '5.0.1', '2.28.2')
87+
ciUtil.updateGithubCommitStatus(repoName, stage3, 'SUCCESS', 'success', commitSha)
88+
} catch (Exception e) {
89+
ciUtil.updateGithubCommitStatus(repoName, stage3, 'FAILURE', 'failure', commitSha)
90+
print("${stage3} failed")
91+
throw e
92+
}
93+
}
94+
}
95+
parallel workflows
96+
}
97+
}
98+
}
99+
}
100+
post {
101+
success {
102+
script {
103+
ciUtil.updateGithubCommitStatus(repoName, statusContext, currentBuild.currentResult, 'success', commitSha)
104+
}
105+
}
106+
unsuccessful {
107+
script {
108+
ciUtil.updateGithubCommitStatus(repoName, statusContext, currentBuild.currentResult, 'failure', commitSha)
109+
ciUtil.notifySlack(repoName, commitSha)
110+
}
111+
}
112+
always {
113+
script {
114+
stackdriver.updatePipelineStatistics(this)
115+
}
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)