-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI-15490 Create Jenkins CI pipeline (#109)
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |