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

188 lines
6.9 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:46:29 +00:00
def myParams = [:];
2018-03-27 07:12:19 +00:00
// Copy configured params
for (entry in params) {
myParams[entry.key] = entry.value;
}
2018-03-29 06:46:49 +00:00
// Is this a LONG test?
if ("${env.JOB_NAME}" == "kube-arangodb-long") {
myParams["LONG"] = true;
2018-08-09 13:00:16 +00:00
myParams["KUBECONFIGS"] = "gke-jenkins-1";
2018-03-29 06:46:49 +00:00
}
2018-03-27 07:12:19 +00:00
// Fetch params configured in git commit messages
// Syntax: [ci OPT=value]
// Example: [ci TESTOPTIONS="-test.run ^TestSimpleSingle$"]
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) {
def idx = opt.indexOf('=');
if (idx > 0) {
2018-03-27 07:06:46 +00:00
def key = opt.substring(0, idx);
2018-03-27 08:23:43 +00:00
def value = opt.substring(idx+1).replaceAll('^\"|\"$', '');
2018-03-27 07:12:19 +00:00
myParams[key] = value;
2018-03-27 08:31:38 +00:00
//println("Overwriting myParams.${key} with ${value}");
}
}
2018-03-27 08:31:38 +00:00
// Show params in log
for (entry in myParams) {
println("Using myParams.${entry.key} with ${entry.value}");
}
2018-03-27 07:46:29 +00:00
return myParams;
}
2018-03-08 12:19:27 +00:00
def kubeConfigRoot = "/home/jenkins/.kube"
2018-03-27 08:08:21 +00:00
def buildBuildSteps(Map myParams) {
return {
timestamps {
2018-06-14 13:44:09 +00:00
timeout(time: 15) {
withEnv([
"DEPLOYMENTNAMESPACE=${myParams.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${myParams.DOCKERNAMESPACE}",
"IMAGETAG=jenkins-test",
"LONG=${myParams.LONG ? 1 : 0}",
"TESTOPTIONS=${myParams.TESTOPTIONS}",
]) {
sh "make clean"
sh "make"
sh "make run-unit-tests"
sh "make docker-test"
}
2018-03-27 08:08:21 +00:00
}
}
}
}
2018-03-27 07:46:29 +00:00
def buildTestSteps(Map myParams, String kubeConfigRoot, String kubeconfig) {
return {
timestamps {
2018-06-14 13:44:09 +00:00
timeout(time: myParams.LONG ? 180 : 30) {
withCredentials([
string(credentialsId: 'ENTERPRISEIMAGE', variable: 'DEFAULTENTERPRISEIMAGE'),
string(credentialsId: 'ENTERPRISELICENSE', variable: 'DEFAULTENTERPRISELICENSE'),
]) {
2018-06-14 13:44:09 +00:00
withEnv([
"CLEANDEPLOYMENTS=1",
"DEPLOYMENTNAMESPACE=${myParams.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${myParams.DOCKERNAMESPACE}",
"ENTERPRISEIMAGE=${myParams.ENTERPRISEIMAGE}",
"ENTERPRISELICENSE=${myParams.ENTERPRISELICENSE}",
"ARANGODIMAGE=${myParams.ARANGODIMAGE}",
2018-06-14 13:44:09 +00:00
"IMAGETAG=jenkins-test",
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
"LONG=${myParams.LONG ? 1 : 0}",
"TESTOPTIONS=${myParams.TESTOPTIONS}",
]) {
sh "make run-tests"
}
}
}
}
}
}
2018-03-27 07:46:29 +00:00
def buildCleanupSteps(Map myParams, String kubeConfigRoot, String kubeconfig) {
return {
timestamps {
2018-06-14 13:44:09 +00:00
timeout(time: 15) {
withEnv([
"DEPLOYMENTNAMESPACE=${myParams.TESTNAMESPACE}-${env.GIT_COMMIT}",
"DOCKERNAMESPACE=${myParams.DOCKERNAMESPACE}",
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
]) {
sh "./scripts/collect_logs.sh ${env.DEPLOYMENTNAMESPACE} ${kubeconfig}"
archive includes: 'logs/*'
sh "make cleanup-tests"
}
}
}
}
}
2018-03-27 07:58:49 +00:00
pipeline {
options {
2018-02-20 10:28:55 +00:00
buildDiscarder(logRotator(daysToKeepStr: '7', numToKeepStr: '10'))
2018-03-13 15:25:33 +00:00
lock resource: 'kube-arangodb'
2018-03-27 07:58:49 +00:00
}
agent any
2018-02-20 10:28:55 +00:00
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!!)', )
string(name: 'ENTERPRISEIMAGE', defaultValue: '', description: 'ENTERPRISEIMAGE sets the docker image used for enterprise tests', )
string(name: 'ARANGODIMAGE', defaultValue: '', description: 'ARANGODIMAGE sets the docker image used for tests (except enterprise and update tests)', )
string(name: 'ENTERPRISELICENSE', defaultValue: '', description: 'ENTERPRISELICENSE sets the enterprise license key for enterprise tests', )
string(name: 'TESTOPTIONS', defaultValue: '', description: 'TESTOPTIONS is used to pass additional test options to the integration test', )
2018-02-20 10:28:55 +00:00
}
2018-03-27 07:58:49 +00:00
stages {
2018-02-20 10:28:55 +00:00
stage('Build') {
steps {
2018-03-27 08:08:21 +00:00
script {
def myParams = fetchParamsFromGitLog();
def buildSteps = buildBuildSteps(myParams);
buildSteps();
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-27 08:08:21 +00:00
def myParams = fetchParamsFromGitLog();
2018-03-27 08:16:11 +00:00
def configs = "${myParams.KUBECONFIGS}".split(",")
2018-03-08 12:11:43 +00:00
def testTasks = [:]
for (kubeconfig in configs) {
2018-03-27 07:46:29 +00:00
testTasks["${kubeconfig}"] = buildTestSteps(myParams, 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
}
}
}
2018-03-27 07:58:49 +00:00
}
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-27 08:08:21 +00:00
def myParams = fetchParamsFromGitLog();
2018-03-27 07:18:34 +00:00
def configs = "${myParams['KUBECONFIGS']}".split(",")
2018-03-08 12:11:43 +00:00
def cleanupTasks = [:]
for (kubeconfig in configs) {
2018-03-27 07:46:29 +00:00
cleanupTasks["${kubeconfig}"] = buildCleanupSteps(myParams, 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')
}
}
}