Skip to content

Commit a12291c

Browse files
caladdbsanders
authored andcommitted
INTERNAL: Auto-merge in Python module updates
Adds a stage to the Jenkinsfile, which will merge an updates branch into `develop` once all platforms have passed. This stage only runs on the redhat7 version of the pipeline, because it is the last to complete. Also had to refactor some of the `pipeline` into Groovy functions, because of limitations on the size of a single `pipeline` when converting from Groovy to Java. But, it helped remove some duplicated code, so it was a net positive.
1 parent 60c49ce commit a12291c

1 file changed

Lines changed: 106 additions & 108 deletions

File tree

Jenkinsfile

Lines changed: 106 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ pipeline {
55

66
environment {
77
TD_GITHUB = credentials('cbaa2c3c-151e-4ba2-92ed-8f088762467b')
8+
GITHUB = credentials('88f234ac-6b93-4c41-92d2-1329c97e2254')
89
ARTIFACTORY = credentials('d1a4e414-0526-4973-bea5-9d219d884f03')
910
GITHUB_TOKEN = credentials('72702790-6cee-470b-94d0-1c3eb246a71d')
1011
BLACKDUCK_TOKEN = credentials('cb9c5430-f974-46e3-9d25-baeab4873db9')
1112
ESXI_PASS = credentials('8af95130-9b78-4e7a-9d3a-bec7ab54716b')
13+
JENKINS = credentials('8b24c6e2-8589-4feb-afc2-3d0175854b11')
1214

1315
PIPELINE = env.JOB_NAME.split('/')[0].trim()
1416
PLATFORM = env.PIPELINE.split('-')[-1].trim()
@@ -551,46 +553,12 @@ pipeline {
551553
}
552554

553555
steps {
554-
// Run the integration tests
555-
dir('integration_1') {
556-
// Give the tests up to 90 minutes to finish
557-
timeout(90) {
558-
script {
559-
try {
560-
if (env.COVERAGE_REPORTS == 'true') {
561-
sh './run-tests.sh --integration --coverage --test-group-count=3 --test-group=1 ../$ISO_FILENAME'
562-
}
563-
else {
564-
sh './run-tests.sh --integration --test-group-count=3 --test-group=1 ../$ISO_FILENAME'
565-
}
566-
}
567-
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
568-
// Make sure we clean up the VM
569-
dir('test-suites/integration') {
570-
sh 'vagrant destroy -f || true'
571-
}
572-
573-
// Raise an error
574-
error 'Integration Group 1 test-suite timed out'
575-
}
576-
}
577-
}
578-
}
556+
run_integration_test_steps('1', '3')
579557
}
580558

581559
post {
582560
always {
583-
script {
584-
// Record the test statuses for Jenkins
585-
if (fileExists('integration_1/reports/integration-junit.xml')) {
586-
junit 'integration_1/reports/integration-junit.xml'
587-
}
588-
589-
if (env.COVERAGE_REPORTS == 'true') {
590-
// Add the coverage data to the `combine` folder
591-
sh 'mv integration_1/reports/integration.coverage combine/reports/integration-1.coverage'
592-
}
593-
}
561+
run_integration_test_post('1')
594562
}
595563
}
596564
}
@@ -603,46 +571,12 @@ pipeline {
603571
}
604572

605573
steps {
606-
// Run the integration tests
607-
dir('integration_2') {
608-
// Give the tests up to 90 minutes to finish
609-
timeout(90) {
610-
script {
611-
try {
612-
if (env.COVERAGE_REPORTS == 'true') {
613-
sh './run-tests.sh --integration --coverage --test-group-count=3 --test-group=2 ../$ISO_FILENAME'
614-
}
615-
else {
616-
sh './run-tests.sh --integration --test-group-count=3 --test-group=2 ../$ISO_FILENAME'
617-
}
618-
}
619-
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
620-
// Make sure we clean up the VM
621-
dir('test-suites/integration') {
622-
sh 'vagrant destroy -f || true'
623-
}
624-
625-
// Raise an error
626-
error 'Integration Group 2 test-suite timed out'
627-
}
628-
}
629-
}
630-
}
574+
run_integration_test_steps('2', '3')
631575
}
632576

633577
post {
634578
always {
635-
script {
636-
// Record the test statuses for Jenkins
637-
if (fileExists('integration_2/reports/integration-junit.xml')) {
638-
junit 'integration_2/reports/integration-junit.xml'
639-
}
640-
641-
if (env.COVERAGE_REPORTS == 'true') {
642-
// Add the coverage data to the `combine` folder
643-
sh 'mv integration_2/reports/integration.coverage combine/reports/integration-2.coverage'
644-
}
645-
}
579+
run_integration_test_post('2')
646580
}
647581
}
648582
}
@@ -655,46 +589,12 @@ pipeline {
655589
}
656590

657591
steps {
658-
// Run the integration tests
659-
dir('integration_3') {
660-
// Give the tests up to 90 minutes to finish
661-
timeout(90) {
662-
script {
663-
try {
664-
if (env.COVERAGE_REPORTS == 'true') {
665-
sh './run-tests.sh --integration --coverage --test-group-count=3 --test-group=3 ../$ISO_FILENAME'
666-
}
667-
else {
668-
sh './run-tests.sh --integration --test-group-count=3 --test-group=3 ../$ISO_FILENAME'
669-
}
670-
}
671-
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
672-
// Make sure we clean up the VM
673-
dir('test-suites/integration') {
674-
sh 'vagrant destroy -f || true'
675-
}
676-
677-
// Raise an error
678-
error 'Integration Group 3 test-suite timed out'
679-
}
680-
}
681-
}
682-
}
592+
run_integration_test_steps('3', '3')
683593
}
684594

685595
post {
686596
always {
687-
script {
688-
// Record the test statuses for Jenkins
689-
if (fileExists('integration_3/reports/integration-junit.xml')) {
690-
junit 'integration_3/reports/integration-junit.xml'
691-
}
692-
693-
if (env.COVERAGE_REPORTS == 'true') {
694-
// Add the coverage data to the `combine` folder
695-
sh 'mv integration_3/reports/integration.coverage combine/reports/integration-3.coverage'
696-
}
697-
}
597+
run_integration_test_post('3')
698598
}
699599
}
700600
}
@@ -1453,6 +1353,64 @@ pipeline {
14531353
}
14541354
}
14551355
}
1356+
1357+
stage('Merge') {
1358+
when {
1359+
branch 'feature/updates-*'
1360+
environment name: 'PLATFORM', value: 'redhat7'
1361+
}
1362+
1363+
steps {
1364+
// Poll the status of the other platforms' builds
1365+
retry(20) {
1366+
sh '''
1367+
curl -s --user $JENKINS ${JOB_URL/redhat7/sles15}/lastBuild/api/json?tree=result | grep -q SUCCESS || (STATUS=$? && sleep 60 && exit $STATUS)
1368+
curl -s --user $JENKINS ${JOB_URL/redhat7/sles12}/lastBuild/api/json?tree=result | grep -q SUCCESS || (STATUS=$? && sleep 60 && exit $STATUS)
1369+
curl -s --user $JENKINS ${JOB_URL/redhat7/sles11}/lastBuild/api/json?tree=result | grep -q SUCCESS || (STATUS=$? && sleep 60 && exit $STATUS)
1370+
'''
1371+
}
1372+
1373+
dir('stacki') {
1374+
// Note: Will fail the stage if we can't fast-forward the
1375+
// commit, which will let us deal with merge issues manually
1376+
1377+
// Merge in the update branch via fast-forward
1378+
sh 'git checkout develop'
1379+
sh 'git merge --ff-only $GIT_BRANCH'
1380+
sh 'git push https://${GITHUB}@github.com/Teradata/stacki.git'
1381+
1382+
// Delete the old branch
1383+
sh 'git push https://${GITHUB}@github.com/Teradata/stacki.git --delete $GIT_BRANCH'
1384+
}
1385+
}
1386+
1387+
post {
1388+
failure {
1389+
slackSend(
1390+
channel: '#stacki-bot',
1391+
color: 'danger',
1392+
message: """\
1393+
Stacki merge has failed.
1394+
*Branch:* ${env.GIT_BRANCH}
1395+
<${env.RUN_DISPLAY_URL}|View the pipeline job>
1396+
""".stripIndent(),
1397+
tokenCredentialId: 'slack-token-stacki'
1398+
)
1399+
}
1400+
1401+
success {
1402+
slackSend(
1403+
channel: '#stacki-builds',
1404+
color: 'good',
1405+
message: """\
1406+
Stacki merge has succeeded.
1407+
*Branch:* ${env.GIT_BRANCH}
1408+
""".stripIndent(),
1409+
tokenCredentialId: 'slack-token-stacki'
1410+
)
1411+
}
1412+
}
1413+
}
14561414
}
14571415

14581416
post {
@@ -1462,3 +1420,43 @@ pipeline {
14621420
}
14631421
}
14641422
}
1423+
1424+
def run_integration_test_steps(String group, String count) {
1425+
// Run the integration tests
1426+
dir("integration_$group") {
1427+
// Give the tests up to 90 minutes to finish
1428+
timeout(90) {
1429+
script {
1430+
try {
1431+
if (env.COVERAGE_REPORTS == 'true') {
1432+
sh "./run-tests.sh --integration --coverage --test-group-count=$count --test-group=$group ../\$ISO_FILENAME"
1433+
}
1434+
else {
1435+
sh "./run-tests.sh --integration --test-group-count=$count --test-group=$group ../\$ISO_FILENAME"
1436+
}
1437+
}
1438+
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
1439+
// Make sure we clean up the VM
1440+
dir('test-suites/integration') {
1441+
sh 'vagrant destroy -f || true'
1442+
}
1443+
1444+
// Raise an error
1445+
error "Integration Group $group test-suite timed out"
1446+
}
1447+
}
1448+
}
1449+
}
1450+
}
1451+
1452+
def run_integration_test_post(String group) {
1453+
// Record the test statuses for Jenkins
1454+
if (fileExists("integration_$group/reports/integration-junit.xml")) {
1455+
junit "integration_$group/reports/integration-junit.xml"
1456+
}
1457+
1458+
if (env.COVERAGE_REPORTS == 'true') {
1459+
// Add the coverage data to the `combine` folder
1460+
sh "mv integration_$group/reports/integration.coverage combine/reports/integration-$group.coverage"
1461+
}
1462+
}

0 commit comments

Comments
 (0)