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 )
}
2018-03-27 07:12:19 +00:00
def myParams = [ : ] ;
2018-03-27 06:53:49 +00:00
def fetchParamsFromGitLog ( ) {
2018-03-27 07:12:19 +00:00
// Copy configured params
for ( entry in params ) {
2018-03-27 07:16:14 +00:00
println ( "Fetching entry from params: ${entry}" ) ;
println ( "Fetching entry from params: key=${entry.key}, value=${entry.value}" ) ;
2018-03-27 07:12:19 +00:00
myParams [ entry . key ] = entry . value ;
}
// 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" )
2018-03-27 06:53:49 +00:00
for ( opt in options ) {
2018-03-27 07:05:50 +00:00
println ( "Processing option ${opt}" ) ;
2018-03-27 06:53:49 +00:00
def idx = opt . indexOf ( '=' ) ;
2018-03-27 07:05:50 +00:00
println ( "Processing option ${opt} with idx=${idx}" ) ;
2018-03-27 06:53:49 +00:00
if ( idx > 0 ) {
2018-03-27 07:06:46 +00:00
def key = opt . substring ( 0 , idx ) ;
def value = opt . substring ( idx + 1 ) ;
2018-03-27 07:12:19 +00:00
myParams [ key ] = value ;
println ( "Overwriting myParams.${key} with ${value}" ) ;
2018-03-27 06:53:49 +00:00
}
}
}
2018-03-08 12:19:27 +00:00
def kubeConfigRoot = "/home/jenkins/.kube"
2018-03-08 12:03:14 +00:00
2018-03-08 12:19:27 +00:00
def buildTestSteps ( String kubeConfigRoot , String kubeconfig ) {
2018-03-08 12:03:14 +00:00
return {
timestamps {
2018-03-13 14:53:39 +00:00
withCredentials ( [ string ( credentialsId: 'ENTERPRISEIMAGE' , variable: 'DEFAULTENTERPRISEIMAGE' ) ] ) {
withEnv ( [
2018-03-27 07:18:34 +00:00
"DEPLOYMENTNAMESPACE=${myParams['TESTNAMESPACE']}-${env.GIT_COMMIT}" ,
"DOCKERNAMESPACE=${myParams['DOCKERNAMESPACE']}" ,
"ENTERPRISEIMAGE=${myParams['ENTERPRISEIMAGE']}" ,
2018-03-13 14:53:39 +00:00
"IMAGETAG=jenkins-test" ,
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}" ,
2018-03-27 07:18:34 +00:00
"LONG=${myParams['LONG'] ? 1 : 0}" ,
"TESTOPTIONS=${myParams['TESTOPTIONS']}" ,
2018-03-13 14:53:39 +00:00
] ) {
sh "make run-tests"
2018-03-08 12:03:14 +00:00
}
}
}
}
}
2018-03-08 12:19:27 +00:00
def buildCleanupSteps ( String kubeConfigRoot , String kubeconfig ) {
2018-03-08 12:03:14 +00:00
return {
timestamps {
2018-03-08 12:07:42 +00:00
withEnv ( [
2018-03-27 07:18:34 +00:00
"DEPLOYMENTNAMESPACE=${myParams['TESTNAMESPACE']}-${env.GIT_COMMIT}" ,
"DOCKERNAMESPACE=${myParams['DOCKERNAMESPACE']}" ,
2018-03-08 12:07:42 +00:00
"KUBECONFIG=${kubeConfigRoot}/${kubeconfig}" ,
] ) {
sh "make cleanup-tests"
2018-03-08 12:03:14 +00:00
}
}
}
}
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' , )
2018-02-22 08:12:36 +00:00
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 {
2018-03-27 06:53:49 +00:00
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-27 07:18:34 +00:00
"DEPLOYMENTNAMESPACE=${myParams['TESTNAMESPACE']}-${env.GIT_COMMIT}" ,
"DOCKERNAMESPACE=${myParams['DOCKERNAMESPACE']}" ,
2018-03-13 14:53:39 +00:00
"IMAGETAG=jenkins-test" ,
2018-03-27 07:18:34 +00:00
"LONG=${myParams['LONG'] ? 1 : 0}" ,
"TESTOPTIONS=${myParams['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-27 07:18:34 +00:00
def configs = "${myParams['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-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-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' )
}
}
}