add ability to tigger smoke tests on arbitrary PR

This commit is contained in:
stefano 2019-11-04 15:31:36 +00:00
parent f7e0ce6f0b
commit 35def14b1f

View File

@ -4,22 +4,24 @@ import static com.r3.build.BuildControl.killAllExistingBuildsForJob
killAllExistingBuildsForJob(env.JOB_NAME, env.BUILD_NUMBER.toInteger()) killAllExistingBuildsForJob(env.JOB_NAME, env.BUILD_NUMBER.toInteger())
pipeline { pipeline {
agent { label 'k8s' }
options { timestamps() }
triggers { triggers {
issueCommentTrigger('.*smoke tests.*') issueCommentTrigger('.*smoke tests.*')
} }
agent { label 'k8s' }
options { timestamps() }
environment { environment {
DOCKER_TAG_TO_USE = "${env.GIT_COMMIT.subSequence(0, 8)}st" DOCKER_TAG_TO_USE = "${env.GIT_COMMIT.subSequence(0, 8)}"
EXECUTOR_NUMBER = "${env.EXECUTOR_NUMBER}" EXECUTOR_NUMBER = "${env.EXECUTOR_NUMBER}"
BUILD_ID = "${env.BUILD_ID}-${env.JOB_NAME}" BUILD_ID = "${env.BUILD_ID}-${env.JOB_NAME}"
ARTIFACTORY_CREDENTIALS = credentials('artifactory-credentials')
} }
stages { stages {
stage('Smoke Tests') { stage('Corda Smoke Tests - Generate Build Image') {
steps { steps {
script { script {
pullRequest.createStatus(status: 'pending', pullRequest.createStatus(status: 'pending',
context: 'continuous-integration/jenkins/pr-merge/smokeTest', context: 'continuous-integration/jenkins/pr-merge/smokeTest',
@ -29,24 +31,50 @@ pipeline {
withCredentials([string(credentialsId: 'container_reg_passwd', variable: 'DOCKER_PUSH_PWD')]) { withCredentials([string(credentialsId: 'container_reg_passwd', variable: 'DOCKER_PUSH_PWD')]) {
sh "./gradlew " + sh "./gradlew " +
"-DbuildId=\"\${BUILD_ID}\" " +
"-Dkubenetize=true " + "-Dkubenetize=true " +
"-DpreAllocatePods=true " +
"-Ddocker.push.password=\"\${DOCKER_PUSH_PWD}\" " + "-Ddocker.push.password=\"\${DOCKER_PUSH_PWD}\" " +
"-Ddocker.work.dir=\"/tmp/\${EXECUTOR_NUMBER}\" " + "-Ddocker.work.dir=\"/tmp/\${EXECUTOR_NUMBER}\" " +
"-Ddocker.build.tag=\"\${DOCKER_TAG_TO_USE}\"" + "-Ddocker.build.tag=\"\${DOCKER_TAG_TO_USE}\"" +
" allParallelSmokeTest" " clean pushBuildImage --stacktrace"
} }
sh "kubectl auth can-i get pods"
}
}
stage('Smoke Tests') {
steps {
script {
pullRequest.createStatus(status: 'pending',
context: 'continuous-integration/jenkins/pr-merge/smokeTest',
description: 'Smoke Tests Running',
targetUrl: "${env.JOB_URL}")
}
sh "./gradlew " +
"-DbuildId=\"\${BUILD_ID}\" " +
"-Dkubenetize=true " +
"-Ddocker.run.tag=\"\${DOCKER_TAG_TO_USE}\" " +
"-Dartifactory.username=\"\${ARTIFACTORY_CREDENTIALS_USR}\" " +
"-Dartifactory.password=\"\${ARTIFACTORY_CREDENTIALS_PSW}\" " +
"-Dgit.branch=\"\${GIT_BRANCH}\" " +
"-Dgit.target.branch=\"\${GIT_BRANCH}\" " +
" allParallelSmokeTest --stacktrace"
} }
} }
} }
post {
post {
always { always {
junit testResults: '**/build/test-results-xml/**/*.xml', allowEmptyResults: false archiveArtifacts artifacts: '**/pod-logs/**/*.log', fingerprint: false
junit '**/build/test-results-xml/**/*.xml'
} }
success { success {
script { script {
pullRequest.createStatus(status: 'success', pullRequest.createStatus(status: 'success',
@ -70,3 +98,17 @@ pipeline {
} }
} }
} }
//@NonCPS
//static def currentBuildTriggeredByComment(){
// def triggerCause = currentBuild.rawBuild.getCause(org.jenkinsci.plugins.pipeline.github.trigger.IssueCommentCause)
// if (triggerCause) {
// echo("Build was started by ${triggerCause.userLogin}, who wrote: " +
// "\"${triggerCause.comment}\", which matches the " +
// "\"${triggerCause.triggerPattern}\" trigger pattern.")
// } else {
// echo('Build was not started by a trigger')
// }
//
// return triggerCause == null
//}