Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests on multiple clusters in parallel #37

Merged
merged 8 commits into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 52 additions & 21 deletions Jenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,50 @@ def notifySlack(String buildStatus = 'STARTED') {
slackSend(color: color, channel: '#status-k8s', message: msg)
}

def kubeConfigRoot = "/home/jenkins/.kube"

def buildTestSteps(String kubeConfigRoot, String kubeconfig) {
return {
timestamps {
lock("${kubeconfig}-${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
withCredentials([string(credentialsId: 'ENTERPRISEIMAGE', variable: 'DEFAULTENTERPRISEIMAGE')]) {
withEnv([
"ENTERPRISEIMAGE=${params.ENTERPRISEIMAGE}",
"IMAGETAG=${env.GIT_COMMIT}",
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
"LONG=${params.LONG ? 1 : 0}",
"PUSHIMAGES=1",
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
]) {
sh "make run-tests"
}
}
}
}
}
}

def buildCleanupSteps(String kubeConfigRoot, String kubeconfig) {
return {
timestamps {
withEnv([
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}",
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
]) {
sh "make cleanup-tests"
}
}
}
}

pipeline {
options {
buildDiscarder(logRotator(daysToKeepStr: '7', numToKeepStr: '10'))
}
agent any
parameters {
booleanParam(name: 'LONG', defaultValue: false, description: 'Execute long running tests')
string(name: 'KUBECONFIG', defaultValue: '/home/jenkins/.kube/scw-183a3b', description: 'KUBECONFIG controls which k8s cluster is used', )
string(name: 'KUBECONFIGS', defaultValue: 'scw-183a3b,c11', 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)', )
}
Expand All @@ -36,44 +72,39 @@ pipeline {
timestamps {
withEnv([
"IMAGETAG=${env.GIT_COMMIT}",
"LONG=${params.LONG ? 1 : 0}",
"PUSHIMAGES=1",
]) {
sh "make"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does execution stop here as soon as the first make fails or will the other steps continue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - execution stops on first fail - https://jenkins.io/doc/pipeline/tour/running-multiple-steps/

sh "make run-unit-tests"
sh "make docker-test"
}
}
}
}
stage('Test') {
steps {
timestamps {
lock("${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
withCredentials([string(credentialsId: 'ENTERPRISEIMAGE', variable: 'DEFAULTENTERPRISEIMAGE')]) {
withEnv([
"ENTERPRISEIMAGE=${params.ENTERPRISEIMAGE}",
"IMAGETAG=${env.GIT_COMMIT}",
"KUBECONFIG=${params.KUBECONFIG}",
"LONG=${params.LONG ? 1 : 0}",
"PUSHIMAGES=1",
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
]) {
sh "make run-tests"
}
}
script {
def configs = "${params.KUBECONFIGS}".split(",")
def testTasks = [:]
for (kubeconfig in configs) {
testTasks["${kubeconfig}"] = buildTestSteps(kubeConfigRoot, kubeconfig)
}
parallel testTasks
}
}
}
}

post {
always {
timestamps {
withEnv([
"KUBECONFIG=${params.KUBECONFIG}",
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
]) {
sh "make cleanup-tests"
script {
def configs = "${params.KUBECONFIGS}".split(",")
def cleanupTasks = [:]
for (kubeconfig in configs) {
cleanupTasks["${kubeconfig}"] = buildCleanupSteps(kubeConfigRoot, kubeconfig)
}
parallel cleanupTasks
}
}
failure {
Expand Down