1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00
kube-arangodb/Jenkinsfile.groovy

145 lines
5 KiB
Groovy
Raw Normal View History

2018-02-20 10:28:55 +00:00
def notifySlack(String buildStatus = 'STARTED') {
// Build status of null means success.
buildStatus = buildStatus ?: 'SUCCESS'
def color
if (buildStatus == 'STARTED') {
color = '#D4DADF'
} else if (buildStatus == 'SUCCESS') {
color = '#BDFFC3'
} else if (buildStatus == 'UNSTABLE') {
color = '#FFFE89'
} else {
color = '#FF9FA1'
}
def msg = "${buildStatus}: `${env.JOB_NAME}` #${env.BUILD_NUMBER}: ${env.GIT_COMMIT}\n${env.BUILD_URL}"
slackSend(color: color, channel: '#status-k8s', message: msg)
}
def fetchParamsFromGitLog() {
2018-03-27 07:03:16 +00:00
def options = sh(returnStdout: true, script: "git log --reverse remotes/origin/master..HEAD | grep -o \'\\[ci[^\\[]*\\]\' | sed -E \'s/\\[ci (.*)\\]/\\1/\'").trim().split("\n")
for (opt in options) {
2018-03-27 07:05:50 +00:00
println("Processing option ${opt}");
def idx = opt.indexOf('=');
2018-03-27 07:05:50 +00:00
println("Processing option ${opt} with idx=${idx}");
if (idx > 0) {
2018-03-27 07:06:46 +00:00
def key = opt.substring(0, idx);
def value = opt.substring(idx+1);
params[key] = value;
println("Overwriting params.${key} with ${value}");
}
}
}
2018-03-08 12:19:27 +00:00
def kubeConfigRoot = "/home/jenkins/.kube"
2018-03-08 12:19:27 +00:00
def buildTestSteps(String kubeConfigRoot, String kubeconfig) {
return {
timestamps {
withCredentials([string(credentialsId: 'ENTERPRISEIMAGE', variable: 'DEFAULTENTERPRISEIMAGE')]) {
withEnv([
"DEPLOYMENTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${params.DOCKERNAMESPACE}",
"ENTERPRISEIMAGE=${params.ENTERPRISEIMAGE}",
"IMAGETAG=jenkins-test",
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
"LONG=${params.LONG ? 1 : 0}",
"TESTOPTIONS=${params.TESTOPTIONS}",
]) {
sh "make run-tests"
}
}
}
}
}
2018-03-08 12:19:27 +00:00
def buildCleanupSteps(String kubeConfigRoot, String kubeconfig) {
return {
timestamps {
2018-03-08 12:07:42 +00:00
withEnv([
2018-03-13 09:38:03 +00:00
"DEPLOYMENTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${params.DOCKERNAMESPACE}",
2018-03-08 12:07:42 +00:00
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
]) {
sh "make cleanup-tests"
}
}
}
}
2018-02-20 10:28:55 +00:00
pipeline {
options {
buildDiscarder(logRotator(daysToKeepStr: '7', numToKeepStr: '10'))
2018-03-13 15:25:33 +00:00
lock resource: 'kube-arangodb'
2018-02-20 10:28:55 +00:00
}
agent any
parameters {
2018-03-01 10:15:18 +00:00
booleanParam(name: 'LONG', defaultValue: false, description: 'Execute long running tests')
2018-03-12 11:18:50 +00:00
string(name: 'DOCKERNAMESPACE', defaultValue: 'arangodb', description: 'DOCKERNAMESPACE sets the docker registry namespace in which the operator docker image will be pushed', )
2018-03-13 13:23:27 +00:00
string(name: 'KUBECONFIGS', defaultValue: 'kube-ams1,scw-183a3b', description: 'KUBECONFIGS is a comma separated list of Kubernetes configuration files (relative to /home/jenkins/.kube) on which the tests are run', )
string(name: 'TESTNAMESPACE', defaultValue: 'jenkins', description: 'TESTNAMESPACE sets the kubernetes namespace to ru tests in (this must be short!!)', )
2018-02-27 08:30:00 +00:00
string(name: 'ENTERPRISEIMAGE', defaultValue: '', description: 'ENTERPRISEIMAGE sets the docker image used for enterprise tests)', )
2018-02-20 10:28:55 +00:00
}
stages {
stage("Prepare") {
steps {
script {
fetchParamsFromGitLog()
}
}
}
2018-02-20 10:28:55 +00:00
stage('Build') {
steps {
timestamps {
2018-02-20 17:53:33 +00:00
withEnv([
2018-03-12 13:16:13 +00:00
"DEPLOYMENTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
2018-03-12 11:18:50 +00:00
"DOCKERNAMESPACE=${params.DOCKERNAMESPACE}",
"IMAGETAG=jenkins-test",
2018-03-08 12:30:42 +00:00
"LONG=${params.LONG ? 1 : 0}",
"TESTOPTIONS=${params.TESTOPTIONS}",
2018-02-20 17:53:33 +00:00
]) {
sh "make"
2018-02-27 14:32:09 +00:00
sh "make run-unit-tests"
2018-03-08 12:30:42 +00:00
sh "make docker-test"
2018-02-20 17:53:33 +00:00
}
2018-02-20 10:28:55 +00:00
}
}
}
stage('Test') {
2018-02-20 10:29:32 +00:00
steps {
2018-03-08 12:11:43 +00:00
script {
2018-03-08 12:14:30 +00:00
def configs = "${params.KUBECONFIGS}".split(",")
2018-03-08 12:11:43 +00:00
def testTasks = [:]
for (kubeconfig in configs) {
2018-03-08 12:19:27 +00:00
testTasks["${kubeconfig}"] = buildTestSteps(kubeConfigRoot, kubeconfig)
2018-02-20 10:28:55 +00:00
}
2018-03-08 12:11:43 +00:00
parallel testTasks
2018-02-20 10:28:55 +00:00
}
}
}
}
post {
2018-02-27 10:31:27 +00:00
always {
2018-03-08 12:11:43 +00:00
script {
2018-03-08 12:14:30 +00:00
def configs = "${params.KUBECONFIGS}".split(",")
2018-03-08 12:11:43 +00:00
def cleanupTasks = [:]
for (kubeconfig in configs) {
2018-03-08 12:19:27 +00:00
cleanupTasks["${kubeconfig}"] = buildCleanupSteps(kubeConfigRoot, kubeconfig)
2018-02-27 10:31:27 +00:00
}
2018-03-08 12:11:43 +00:00
parallel cleanupTasks
2018-02-27 10:31:27 +00:00
}
}
2018-02-20 10:28:55 +00:00
failure {
notifySlack('FAILURE')
}
success {
notifySlack('SUCCESS')
}
}
}