Skip to content

Commit

Permalink
CI-15490 Create Jenkins CI pipeline (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolesu authored May 2, 2024
1 parent 2e5fc6d commit 5671215
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}

0 comments on commit 5671215

Please sign in to comment.