From 4ca9a8e2d2bbc0b900884d04c7cfd30415854df6 Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Tue, 16 Apr 2024 17:40:27 -0700 Subject: [PATCH 1/8] set up --- .jenkins/Jenkinsfile | 116 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .jenkins/Jenkinsfile diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile new file mode 100644 index 0000000..87b664b --- /dev/null +++ b/.jenkins/Jenkinsfile @@ -0,0 +1,116 @@ +// Load Jenkins shared library +jenkinsBranch = 'sift-python' +sharedLib = library("shared-lib@${jenkinsBranch}") + +def siftPythonWorkflow = sharedLib.com.sift.ci.SiftPythonWorkflow.new() +def ciUtil = sharedLib.com.sift.ci.CIUtil.new() +def stackdriver = sharedLib.com.sift.ci.StackDriverMetrics.new() + +// Default GitHub status context for automatically triggered builds +def defaultStatusContext = 'Jenkins:auto' + +// Pod template file for Jenkins agent pod +// Pod template yaml file is defined in https://github.com/SiftScience/jenkins/tree/master/resources/jenkins-k8s-pod-templates +def python2PodTemplateFile = 'python-2-7-pod-template.yaml' +def python3PodTemplateFile = 'python-3-10-pod-template.yaml' +def podLabel = "python-${BUILD_TAG}" + + +// GitHub repo name +def repoName = 'sift-python' + +pipeline { + agent none + options { + timestamps() + skipDefaultCheckout() + disableConcurrentBuilds() + parallelsAlwaysFailFast() + buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '') + } + environment { + GIT_BRANCH = "${env.CHANGE_BRANCH != null? env.CHANGE_BRANCH : env.BRANCH_NAME}" + } + stages { + stage('Initialize') { + steps { + script { + statusContext = defaultStatusContext + // Get the commit sha for the build + commitSha = ciUtil.commitHashForBuild() + ciUtil.updateGithubCommitStatus(repoName, statusContext, 'Started', 'pending', commitSha) + } + } + } + stage ('Build and Test Workflows') { + steps { + script { + def workflows = [:] + def stage1 = 'Run Integration Tests - python3' + workflows[stage1] = { + stage(stage1) { + // if (env.GIT_BRANCH.equals('master')) { + ciUtil.updateGithubCommitStatus(repoName, stage1, 'Started', 'pending', commitSha) + try { + siftPythonWorkflow.runSiftPythonIntegration(python3PodTemplateFile, podLabel) + ciUtil.updateGithubCommitStatus(repoName, stage1, 'SUCCESS', 'success', commitSha) + } catch (Exception e) { + ciUtil.updateGithubCommitStatus(repoName, stage1, 'FAILURE', 'failure', commitSha) + print("${stage1} failed") + throw e + } + // } + } + } + def stage2 = 'Build and Test - python2' + workflows[stage2] = { + stage(stage2) { + ciUtil.updateGithubCommitStatus(repoName, stage2, 'Started', 'pending', commitSha) + try { + siftPythonWorkflow.runSiftPythonBuildAndTest(python2PodTemplateFile, podLabel, '3.0.5', '2.27.1') + ciUtil.updateGithubCommitStatus(repoName, stage2, 'SUCCESS', 'success', commitSha) + } catch (Exception e) { + ciUtil.updateGithubCommitStatus(repoName, stage2, 'FAILURE', 'failure', commitSha) + print("${stage2} failed") + throw e + } + } + } + def stage3 = 'Build and Test - python3' + workflows[stage3] = { + stage(stage3) { + ciUtil.updateGithubCommitStatus(repoName, stage3, 'Started', 'pending', commitSha) + try { + siftPythonWorkflow.runSiftPythonBuildAndTest(python3PodTemplateFile, podLabel, '5.0.1', '2.28.2') + ciUtil.updateGithubCommitStatus(repoName, stage3, 'SUCCESS', 'success', commitSha) + } catch (Exception e) { + ciUtil.updateGithubCommitStatus(repoName, stage3, 'FAILURE', 'failure', commitSha) + print("${stage3} failed") + throw e + } + } + } + parallel workflows + } + } + } + } + post { + success { + script { + ciUtil.updateGithubCommitStatus(repoName, statusContext, currentBuild.currentResult, 'success', commitSha) + } + } + unsuccessful { + script { + ciUtil.updateGithubCommitStatus(repoName, statusContext, currentBuild.currentResult, 'failure', commitSha) + ciUtil.notifySlack(repoName, commitSha) + } + } + always { + script { + stackdriver.updatePipelineStatistics(this) + } + } + } +} From f2acbc0bd8bc25fe94a955dba8ee8d29f3de34d8 Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Wed, 17 Apr 2024 14:15:46 -0700 Subject: [PATCH 2/8] add --- .jenkins/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index 87b664b..3d17515 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -49,7 +49,7 @@ pipeline { def stage1 = 'Run Integration Tests - python3' workflows[stage1] = { stage(stage1) { - // if (env.GIT_BRANCH.equals('master')) { + if (env.GIT_BRANCH.equals('master')) { ciUtil.updateGithubCommitStatus(repoName, stage1, 'Started', 'pending', commitSha) try { siftPythonWorkflow.runSiftPythonIntegration(python3PodTemplateFile, podLabel) @@ -59,7 +59,7 @@ pipeline { print("${stage1} failed") throw e } - // } + } } } def stage2 = 'Build and Test - python2' From 4a31880ddd6ea0cebbb84a91c0afcb2de016fa1c Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Wed, 17 Apr 2024 14:27:45 -0700 Subject: [PATCH 3/8] add --- .jenkins/Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index 3d17515..367ac6a 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -13,7 +13,8 @@ def defaultStatusContext = 'Jenkins:auto' // Pod template yaml file is defined in https://github.com/SiftScience/jenkins/tree/master/resources/jenkins-k8s-pod-templates def python2PodTemplateFile = 'python-2-7-pod-template.yaml' def python3PodTemplateFile = 'python-3-10-pod-template.yaml' -def podLabel = "python-${BUILD_TAG}" +def python2PodLabel = "python3-${BUILD_TAG}" +def python3PodLabel = "python3-${BUILD_TAG}" // GitHub repo name @@ -52,7 +53,7 @@ pipeline { if (env.GIT_BRANCH.equals('master')) { ciUtil.updateGithubCommitStatus(repoName, stage1, 'Started', 'pending', commitSha) try { - siftPythonWorkflow.runSiftPythonIntegration(python3PodTemplateFile, podLabel) + siftPythonWorkflow.runSiftPythonIntegration(python3PodTemplateFile, python3PodLabel) ciUtil.updateGithubCommitStatus(repoName, stage1, 'SUCCESS', 'success', commitSha) } catch (Exception e) { ciUtil.updateGithubCommitStatus(repoName, stage1, 'FAILURE', 'failure', commitSha) @@ -67,7 +68,7 @@ pipeline { stage(stage2) { ciUtil.updateGithubCommitStatus(repoName, stage2, 'Started', 'pending', commitSha) try { - siftPythonWorkflow.runSiftPythonBuildAndTest(python2PodTemplateFile, podLabel, '3.0.5', '2.27.1') + siftPythonWorkflow.runSiftPythonBuildAndTest(python2PodTemplateFile, python2PodLabel, '3.0.5', '2.27.1') ciUtil.updateGithubCommitStatus(repoName, stage2, 'SUCCESS', 'success', commitSha) } catch (Exception e) { ciUtil.updateGithubCommitStatus(repoName, stage2, 'FAILURE', 'failure', commitSha) @@ -81,7 +82,7 @@ pipeline { stage(stage3) { ciUtil.updateGithubCommitStatus(repoName, stage3, 'Started', 'pending', commitSha) try { - siftPythonWorkflow.runSiftPythonBuildAndTest(python3PodTemplateFile, podLabel, '5.0.1', '2.28.2') + siftPythonWorkflow.runSiftPythonBuildAndTest(python3PodTemplateFile, python3PodLabel, '5.0.1', '2.28.2') ciUtil.updateGithubCommitStatus(repoName, stage3, 'SUCCESS', 'success', commitSha) } catch (Exception e) { ciUtil.updateGithubCommitStatus(repoName, stage3, 'FAILURE', 'failure', commitSha) From 1fa1531728cd05ad5893bbf96ba99b6895947622 Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Wed, 17 Apr 2024 14:32:20 -0700 Subject: [PATCH 4/8] add --- .jenkins/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index 367ac6a..f56277c 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -13,7 +13,7 @@ def defaultStatusContext = 'Jenkins:auto' // Pod template yaml file is defined in https://github.com/SiftScience/jenkins/tree/master/resources/jenkins-k8s-pod-templates def python2PodTemplateFile = 'python-2-7-pod-template.yaml' def python3PodTemplateFile = 'python-3-10-pod-template.yaml' -def python2PodLabel = "python3-${BUILD_TAG}" +def python2PodLabel = "python2-${BUILD_TAG}" def python3PodLabel = "python3-${BUILD_TAG}" From 0b8fc55babd7d7510b43aa12dd1c42fcff43653a Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Wed, 17 Apr 2024 14:37:17 -0700 Subject: [PATCH 5/8] test --- .jenkins/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index f56277c..c3c7ca1 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -50,7 +50,7 @@ pipeline { def stage1 = 'Run Integration Tests - python3' workflows[stage1] = { stage(stage1) { - if (env.GIT_BRANCH.equals('master')) { + // if (env.GIT_BRANCH.equals('master')) { ciUtil.updateGithubCommitStatus(repoName, stage1, 'Started', 'pending', commitSha) try { siftPythonWorkflow.runSiftPythonIntegration(python3PodTemplateFile, python3PodLabel) @@ -60,7 +60,7 @@ pipeline { print("${stage1} failed") throw e } - } + // } } } def stage2 = 'Build and Test - python2' From 7f2676863684c84a38e0fe7d8a278c6b32830223 Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Wed, 17 Apr 2024 14:46:32 -0700 Subject: [PATCH 6/8] final --- .jenkins/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index c3c7ca1..f56277c 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -50,7 +50,7 @@ pipeline { def stage1 = 'Run Integration Tests - python3' workflows[stage1] = { stage(stage1) { - // if (env.GIT_BRANCH.equals('master')) { + if (env.GIT_BRANCH.equals('master')) { ciUtil.updateGithubCommitStatus(repoName, stage1, 'Started', 'pending', commitSha) try { siftPythonWorkflow.runSiftPythonIntegration(python3PodTemplateFile, python3PodLabel) @@ -60,7 +60,7 @@ pipeline { print("${stage1} failed") throw e } - // } + } } } def stage2 = 'Build and Test - python2' From aa030e3923867d2e4b3b0792bb3b45590070f2c5 Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Wed, 17 Apr 2024 17:04:01 -0700 Subject: [PATCH 7/8] Update Jenkinsfile --- .jenkins/Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index f56277c..99616b7 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -26,6 +26,7 @@ pipeline { timestamps() skipDefaultCheckout() disableConcurrentBuilds() + disableRestartFromStage() parallelsAlwaysFailFast() buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '') } From ae2815adb7cc6b13d6fdabdfe3c113386325b52f Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Thu, 18 Apr 2024 09:42:47 -0700 Subject: [PATCH 8/8] master --- .jenkins/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile index 99616b7..70b63bf 100644 --- a/.jenkins/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -1,5 +1,5 @@ // Load Jenkins shared library -jenkinsBranch = 'sift-python' +jenkinsBranch = 'master' sharedLib = library("shared-lib@${jenkinsBranch}") def siftPythonWorkflow = sharedLib.com.sift.ci.SiftPythonWorkflow.new()