From 56712157158b3bda459ad6f5187b59d73bf00908 Mon Sep 17 00:00:00 2001 From: Nicole Su Date: Thu, 2 May 2024 11:02:31 -0700 Subject: [PATCH] CI-15490 Create Jenkins CI pipeline (#109) --- .jenkins/Jenkinsfile | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .jenkins/Jenkinsfile diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile new file mode 100644 index 0000000..1fc96ce --- /dev/null +++ b/.jenkins/Jenkinsfile @@ -0,0 +1,80 @@ +// Load Jenkins shared library +jenkinsBranch = 'v0.17.0' +sharedLib = library("shared-lib@${jenkinsBranch}") + +def siftAndroidWorkflow = sharedLib.com.sift.ci.SiftAndroidWorkflow.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 podTemplateFile = 'android-pod-template.yaml' +def podLabel = "android-${BUILD_TAG}" + +// GitHub repo name +def repoName = 'sift-android' + +pipeline { + agent none + options { + timestamps() + skipDefaultCheckout() + disableConcurrentBuilds() + disableRestartFromStage() + parallelsAlwaysFailFast() + buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '') + timeout(time: 30, unit: 'MINUTES') + + } + environment { + GIT_BRANCH = "${env.CHANGE_BRANCH != null? env.CHANGE_BRANCH : env.BRANCH_NAME}" + CACHE_VERSION = 'v1' + } + 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') { + steps { + script { + ciUtil.updateGithubCommitStatus(repoName, 'Build', 'Started', 'pending', commitSha) + try { + siftAndroidWorkflow.runSiftAndroidBuild(podTemplateFile, podLabel) + ciUtil.updateGithubCommitStatus(repoName, 'Build', 'SUCCESS', 'success', commitSha) + } catch (Exception e) { + ciUtil.updateGithubCommitStatus(repoName, 'Build', 'FAILURE', 'failure', commitSha) + throw e + } + } + } + } + } + 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) + } + } + } +}