From b52b0b55c1f02e31fceda31c33090d13b0ee1c61 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 25 Apr 2019 11:52:00 -0300 Subject: [PATCH 1/4] jenkins test --- Jenkinsfile | 227 ++++++++++++++++++++++++++-------------------------- 1 file changed, 113 insertions(+), 114 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 36ce3da4f31..c6d6cd3b582 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,6 @@ pipeline { DRUPAL_THEMES_ROOT = "$DRUPAL_SITES_ALL/themes" CIVICRM_EXT_ROOT = "$DRUPAL_MODULES_ROOT/civicrm/tools/extensions" WEBURL = "http://jenkins.compucorp.co.uk:8900" - ADMIN_PASS = credentials('CVHR_ADMIN_PASS') KARMA_TESTS_REPORT_FOLDER = "reports/js-karma" PHPUNIT_TESTS_REPORT_FOLDER = "reports/phpunit" } @@ -45,119 +44,119 @@ pipeline { } } - stage('Build site') { - steps { - script { - // Build site with CV Buildkit - sh "civibuild create ${params.CIVIHR_BUILDNAME} --type drupal-clean --civi-ver 5.3.1 --url $WEBURL --admin-pass $ADMIN_PASS" - - // Get target and PR branches name - def prBranch = env.CHANGE_BRANCH - def envBranch = env.CHANGE_TARGET ? env.CHANGE_TARGET : env.BRANCH_NAME - if (prBranch != null && prBranch.startsWith("hotfix-")) { - envBranch = 'master' - } - - // Clone CiviHR - cloneCiviHRRepositories(envBranch) - - if (prBranch) { - checkoutPrBranchInCiviHRRepos(prBranch) - mergeEnvBranchInAllRepos(envBranch) - } - - applyCoreForkPatch() - - // The JS tests use the cv tool to find the path of an extension. - // For it to work, the extensions have to be installed on the site - installCiviHRExtensions() - } - } - } - - stage('Run tests') { - parallel { - stage('Test PHP') { - steps { - script { - for (item in mapToList(listCivihrExtensions())) { - def extension = item.value - - if (extension.hasPHPTests) { - testPHPUnit(extension) - } - } - } - } - post { - always { - step([ - $class: 'XUnitBuilder', - thresholds: [ - [ - $class: 'FailedThreshold', - failureNewThreshold: '0', - failureThreshold: '0', - unstableNewThreshold: '0', - unstableThreshold: '0' - ] - ], - tools: [ - [ - $class: 'JUnitType', - pattern: env.PHPUNIT_TESTS_REPORT_FOLDER + '/*.xml' - ] - ] - ]) - } - } - } - - stage('Test JS') { - steps { - script { - installNodePackages(); - - // HRCore is the extension where the JS tests are ran from - def hrcore = listCivihrExtensions().hrcore; - - // This is necessary to avoid an additional loop - // in each extension folder to read the XML. - // After each test we move the reports to this folder - sh "mkdir -p $WORKSPACE/$KARMA_TESTS_REPORT_FOLDER" - - for (item in mapToList(listCivihrExtensions())) { - def extension = item.value - - if (extension.hasJSTests) { - testJS(hrcore.folder, extension) - } - } - } - } - post { - always { - step([ - $class: 'XUnitBuilder', - thresholds: [ - [ - $class: 'FailedThreshold', - failureNewThreshold: '0', - failureThreshold: '0', - unstableNewThreshold: '0', - unstableThreshold: '0' - ] - ], - tools: [ - [ - $class: 'JUnitType', - pattern: env.KARMA_TESTS_REPORT_FOLDER + '/*.xml' - ] - ] - ]) - } - } - } +// stage('Build site') { +// steps { +// script { +// // Build site with CV Buildkit +// sh "civibuild create ${params.CIVIHR_BUILDNAME} --type drupal-clean --civi-ver 5.3.1 --url $WEBURL" +// +// // Get target and PR branches name +// def prBranch = env.CHANGE_BRANCH +// def envBranch = env.CHANGE_TARGET ? env.CHANGE_TARGET : env.BRANCH_NAME +// if (prBranch != null && prBranch.startsWith("hotfix-")) { +// envBranch = 'master' +// } +// +// // Clone CiviHR +// cloneCiviHRRepositories(envBranch) +// +// if (prBranch) { +// checkoutPrBranchInCiviHRRepos(prBranch) +// mergeEnvBranchInAllRepos(envBranch) +// } +// +// applyCoreForkPatch() +// +// // The JS tests use the cv tool to find the path of an extension. +// // For it to work, the extensions have to be installed on the site +// installCiviHRExtensions() +// } +// } +// } +// +// stage('Run tests') { +// parallel { +// stage('Test PHP') { +// steps { +// script { +// for (item in mapToList(listCivihrExtensions())) { +// def extension = item.value +// +// if (extension.hasPHPTests) { +// testPHPUnit(extension) +// } +// } +// } +// } +// post { +// always { +// step([ +// $class: 'XUnitBuilder', +// thresholds: [ +// [ +// $class: 'FailedThreshold', +// failureNewThreshold: '0', +// failureThreshold: '0', +// unstableNewThreshold: '0', +// unstableThreshold: '0' +// ] +// ], +// tools: [ +// [ +// $class: 'JUnitType', +// pattern: env.PHPUNIT_TESTS_REPORT_FOLDER + '/*.xml' +// ] +// ] +// ]) +// } +// } +// } +// +// stage('Test JS') { +// steps { +// script { +// installNodePackages(); +// +// // HRCore is the extension where the JS tests are ran from +// def hrcore = listCivihrExtensions().hrcore; +// +// // This is necessary to avoid an additional loop +// // in each extension folder to read the XML. +// // After each test we move the reports to this folder +// sh "mkdir -p $WORKSPACE/$KARMA_TESTS_REPORT_FOLDER" +// +// for (item in mapToList(listCivihrExtensions())) { +// def extension = item.value +// +// if (extension.hasJSTests) { +// testJS(hrcore.folder, extension) +// } +// } +// } +// } +// post { +// always { +// step([ +// $class: 'XUnitBuilder', +// thresholds: [ +// [ +// $class: 'FailedThreshold', +// failureNewThreshold: '0', +// failureThreshold: '0', +// unstableNewThreshold: '0', +// unstableThreshold: '0' +// ] +// ], +// tools: [ +// [ +// $class: 'JUnitType', +// pattern: env.KARMA_TESTS_REPORT_FOLDER + '/*.xml' +// ] +// ] +// ]) +// } +// } +// } } } } From 1a63bb44459dace253aea6bf78247f5e6f3b8169 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 25 Apr 2019 11:57:01 -0300 Subject: [PATCH 2/4] jenkins test 2 --- Jenkinsfile | 116 ---------------------------------------------------- 1 file changed, 116 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c6d6cd3b582..4384c71052f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -43,122 +43,6 @@ pipeline { sh "rm -f $WORKSPACE/$PHPUNIT_TESTS_REPORT_FOLDER/* || true" } } - -// stage('Build site') { -// steps { -// script { -// // Build site with CV Buildkit -// sh "civibuild create ${params.CIVIHR_BUILDNAME} --type drupal-clean --civi-ver 5.3.1 --url $WEBURL" -// -// // Get target and PR branches name -// def prBranch = env.CHANGE_BRANCH -// def envBranch = env.CHANGE_TARGET ? env.CHANGE_TARGET : env.BRANCH_NAME -// if (prBranch != null && prBranch.startsWith("hotfix-")) { -// envBranch = 'master' -// } -// -// // Clone CiviHR -// cloneCiviHRRepositories(envBranch) -// -// if (prBranch) { -// checkoutPrBranchInCiviHRRepos(prBranch) -// mergeEnvBranchInAllRepos(envBranch) -// } -// -// applyCoreForkPatch() -// -// // The JS tests use the cv tool to find the path of an extension. -// // For it to work, the extensions have to be installed on the site -// installCiviHRExtensions() -// } -// } -// } -// -// stage('Run tests') { -// parallel { -// stage('Test PHP') { -// steps { -// script { -// for (item in mapToList(listCivihrExtensions())) { -// def extension = item.value -// -// if (extension.hasPHPTests) { -// testPHPUnit(extension) -// } -// } -// } -// } -// post { -// always { -// step([ -// $class: 'XUnitBuilder', -// thresholds: [ -// [ -// $class: 'FailedThreshold', -// failureNewThreshold: '0', -// failureThreshold: '0', -// unstableNewThreshold: '0', -// unstableThreshold: '0' -// ] -// ], -// tools: [ -// [ -// $class: 'JUnitType', -// pattern: env.PHPUNIT_TESTS_REPORT_FOLDER + '/*.xml' -// ] -// ] -// ]) -// } -// } -// } -// -// stage('Test JS') { -// steps { -// script { -// installNodePackages(); -// -// // HRCore is the extension where the JS tests are ran from -// def hrcore = listCivihrExtensions().hrcore; -// -// // This is necessary to avoid an additional loop -// // in each extension folder to read the XML. -// // After each test we move the reports to this folder -// sh "mkdir -p $WORKSPACE/$KARMA_TESTS_REPORT_FOLDER" -// -// for (item in mapToList(listCivihrExtensions())) { -// def extension = item.value -// -// if (extension.hasJSTests) { -// testJS(hrcore.folder, extension) -// } -// } -// } -// } -// post { -// always { -// step([ -// $class: 'XUnitBuilder', -// thresholds: [ -// [ -// $class: 'FailedThreshold', -// failureNewThreshold: '0', -// failureThreshold: '0', -// unstableNewThreshold: '0', -// unstableThreshold: '0' -// ] -// ], -// tools: [ -// [ -// $class: 'JUnitType', -// pattern: env.KARMA_TESTS_REPORT_FOLDER + '/*.xml' -// ] -// ] -// ]) -// } -// } -// } - } - } } post { From 21d8e7a12b2a695c1ec6870a1c036bdbd07b6fb0 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 25 Apr 2019 13:52:42 -0300 Subject: [PATCH 3/4] jenkins test 3 --- Jenkinsfile | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4384c71052f..cb2df5ecc7b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,6 +17,7 @@ pipeline { WEBURL = "http://jenkins.compucorp.co.uk:8900" KARMA_TESTS_REPORT_FOLDER = "reports/js-karma" PHPUNIT_TESTS_REPORT_FOLDER = "reports/phpunit" + GIT_URL = "https://github.com/compucorp/civihr" } stages { @@ -68,10 +69,8 @@ pipeline { * Sends a notification when the build starts */ def sendBuildStartNotification() { - def msgHipChat = 'Building ' + getBuildTargetLink('hipchat') + '. ' + getReportLink('hipchat') def msgSlack = 'Building ' + getBuildTargetLink('slack') + '. ' + getReportLink('slack') - sendHipchatNotification('YELLOW', msgHipChat) sendSlackNotification('warning', msgSlack) } @@ -79,10 +78,8 @@ def sendBuildStartNotification() { * Sends a notification when the build is completed successfully */ def sendBuildSuccessNotification() { - def msgHipChat = getBuildTargetLink('hipchat') + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink('hipchat') def msgSlack = getBuildTargetLink('slack') + ' built successfully. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack') - sendHipchatNotification('GREEN', msgHipChat) sendSlackNotification('good', msgSlack) } @@ -90,20 +87,11 @@ def sendBuildSuccessNotification() { * Sends a notification when the build fails */ def sendBuildFailureNotification() { - def msgHipChat = 'Failed to build ' + getBuildTargetLink('hipchat') + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink('hipchat') def msgSlack = 'Failed to build ' + getBuildTargetLink('slack') + '. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack') - sendHipchatNotification('RED', msgHipChat) sendSlackNotification('danger', msgSlack) } -/* - * Sends a notification to Hipchat - */ -def sendHipchatNotification(String color, String message) { - hipchatSend color: color, message: message, notify: true -} - /* * Sends a notification to Slack */ @@ -127,9 +115,6 @@ def getBuildTargetLink(String client) { def forPR = buildIsForAPullRequest() switch (client) { - case 'hipchat': - link = forPR ? "\"${env.CHANGE_TITLE}\"" : '"' + env.BRANCH_NAME + '"' - break; case 'slack': link = forPR ? "<${env.CHANGE_URL}|${env.CHANGE_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>' break; @@ -162,9 +147,6 @@ def getReportLink(String client) { def link = '' switch (client) { - case 'hipchat': - link = 'Click here to see the build report' - break case 'slack': link = "Click <${env.RUN_DISPLAY_URL}|here> to see the build report" break From 821b675982ca6c491f84120a43fb7c1bb5fea970 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 25 Apr 2019 14:30:09 -0300 Subject: [PATCH 4/4] jenkins test 4 --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cb2df5ecc7b..ac04c8fb47d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -116,7 +116,7 @@ def getBuildTargetLink(String client) { switch (client) { case 'slack': - link = forPR ? "<${env.CHANGE_URL}|${env.CHANGE_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>' + link = forPR ? "<${env.GITHUB_PR_URL}|${env.GITHUB_PR_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>' break; } @@ -127,7 +127,7 @@ def getBuildTargetLink(String client) { * Returns true if this build as triggered by a Pull Request. */ def buildIsForAPullRequest() { - return env.CHANGE_URL != null + return env.GITHUB_PR_NUMBER != null } /*