From f67b13f2d7424e5546e74bccaa1f09e3382695c3 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 25 Apr 2019 15:18:29 -0300 Subject: [PATCH 1/7] IN-117: Remove ADMIN_PASS credentials In order to be able to run the tests, we need to create a new civibuild site. However, this site is never really accessed externally and is destroyed after the tests are run, so we don't really care about the admin password and we can just let civibuild create a default one --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 36ce3da4f31..d534e63058d 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" } @@ -49,7 +48,7 @@ pipeline { 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" + 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 From 39cdafa871e7183478efcc3865cdc9dd1d87049e Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 25 Apr 2019 15:24:25 -0300 Subject: [PATCH 2/7] IN-117: Remove support for Hipchat notifications During the transition period from hipchat to slack, having support for both chat clients was interesting as it allowed us to test things on slack while we could still continue using hipchat. Today, hipchat doesn't even exist anymore and we've been using only slack for more than 1 year now, so I'm completely removing support for hipchat to avoid having to maintain the hipchat plugin installed on the Jenkins server --- Jenkinsfile | 42 +++++++----------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d534e63058d..fe5e5e5bf16 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -184,10 +184,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') + def msgSlack = 'Building ' + getBuildTargetLink() + '. ' + getReportLink() - sendHipchatNotification('YELLOW', msgHipChat) sendSlackNotification('warning', msgSlack) } @@ -195,10 +193,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') + def msgSlack = getBuildTargetLink() + ' built successfully. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink() - sendHipchatNotification('GREEN', msgHipChat) sendSlackNotification('good', msgSlack) } @@ -206,20 +202,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') + def msgSlack = 'Failed to build ' + getBuildTargetLink() + '. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink() - 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 */ @@ -238,18 +225,11 @@ def getBuildDuration(build) { * Returns a link to what is being built. If it's a PR, then it's a link to the pull request itself. * If it's a branch, then it's a link in the format http://github.com/org/repo/tree/branch */ -def getBuildTargetLink(String client) { +def getBuildTargetLink() { def link = '' 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; - } + link = forPR ? "<${env.CHANGE_URL}|${env.CHANGE_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>' return link } @@ -274,17 +254,9 @@ def getRepositoryUrlForBuildBranch() { /* * Returns the Blue Ocean build report URL for the current job */ -def getReportLink(String client) { +def getReportLink() { 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 - } + link = "Click <${env.RUN_DISPLAY_URL}|here> to see the build report" return link } From 5a341ed20ca9fad3be7272e9900ab78dff8b66e8 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 25 Apr 2019 15:40:23 -0300 Subject: [PATCH 3/7] IN-117: Update environment variables to support newer versions of Jenkins plugins As part of a Jenkins upgrade and plugins reconfiguration some environments variables stopped being present or had their name changed. Due to that, the Jenkinsfile had to be updated and old variables have been replaced to use the new ones. The GIT_URL variable was removed and there is no equivalent new one, so in this case, on the environment session, we declare a new GITHUB_REPO_URL variable which is used in place of the old one. --- Jenkinsfile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fe5e5e5bf16..7ca89aa0c03 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" + GITHUB_REPO_URL = "https://github.com/compucorp/civihr" } stages { @@ -51,8 +52,8 @@ pipeline { 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 + def prBranch = env.BRANCH_NAME + def envBranch = env.GITHUB_PR_TARGET_BRANCH ? env.GITHUB_PR_TARGET_BRANCH : env.BRANCH_NAME if (prBranch != null && prBranch.startsWith("hotfix-")) { envBranch = 'master' } @@ -229,7 +230,7 @@ def getBuildTargetLink() { def link = '' def forPR = buildIsForAPullRequest() - 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 + '>' return link } @@ -238,17 +239,14 @@ def getBuildTargetLink() { * Returns true if this build as triggered by a Pull Request. */ def buildIsForAPullRequest() { - return env.CHANGE_URL != null + return env.GITHUB_PR_NUMBER != null } /* * Returns a URL pointing to branch currently being built */ def getRepositoryUrlForBuildBranch() { - def repositoryURL = env.GIT_URL - repositoryURL = repositoryURL.replace('.git', '') - - return repositoryURL + '/tree/' + env.BRANCH_NAME + return env.GITHUB_REPO_URL + '/tree/' + env.BRANCH_NAME } /* From 2e47892481d09ca6a8068f16e4a46b9492a2324f Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Fri, 26 Apr 2019 09:15:46 -0300 Subject: [PATCH 4/7] IN-117: Remove debugging code --- Jenkinsfile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7ca89aa0c03..4b3998ae7d6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,18 +25,12 @@ pipeline { steps { sendBuildStartNotification() - // Print all Environment variables - sh 'printenv | sort' - // Update buildkit sh "cd /opt/buildkit && git pull" // Destroy existing site sh "civibuild destroy ${params.CIVIHR_BUILDNAME} || true" - // Test build tools - sh 'amp test' - // Cleanup old Karma test reports sh "rm -f $WORKSPACE/$KARMA_TESTS_REPORT_FOLDER/* || true" From 91291b1b38d34c623db30e4af1e546d01cafbf07 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Fri, 26 Apr 2019 16:01:20 -0300 Subject: [PATCH 5/7] IN-117: Use CiviCRM 5.12.0 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4b3998ae7d6..02683805958 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -43,7 +43,7 @@ pipeline { steps { script { // Build site with CV Buildkit - sh "civibuild create ${params.CIVIHR_BUILDNAME} --type drupal-clean --civi-ver 5.3.1 --url $WEBURL" + sh "civibuild create ${params.CIVIHR_BUILDNAME} --type drupal-clean --civi-ver 5.12.0 --url $WEBURL" // Get target and PR branches name def prBranch = env.BRANCH_NAME From b789ac8448e424673af5906e6048945ed3b40103 Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Fri, 26 Apr 2019 16:16:49 -0300 Subject: [PATCH 6/7] IN-117: Use phpunit5 for tests --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 02683805958..df3a132ba53 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -294,7 +294,7 @@ def testPHPUnit(java.util.LinkedHashMap extension) { sh """ cd $CIVICRM_EXT_ROOT/civihr/${extension.folder} - phpunit4 --testsuite="Unit Tests" --log-junit $WORKSPACE/$PHPUNIT_TESTS_REPORT_FOLDER/result-phpunit_${extension.folder}.xml + phpunit5 --testsuite="Unit Tests" --log-junit $WORKSPACE/$PHPUNIT_TESTS_REPORT_FOLDER/result-phpunit_${extension.folder}.xml """ } From 623f6c9217c42ef1f5c0b8ae67b3cf80f1ea3bae Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Fri, 26 Apr 2019 17:41:54 -0300 Subject: [PATCH 7/7] IN-117: Use PHPUnit as the xunit type --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index df3a132ba53..3725eb0f784 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -98,7 +98,7 @@ pipeline { ], tools: [ [ - $class: 'JUnitType', + $class: 'PHPUnitType', pattern: env.PHPUNIT_TESTS_REPORT_FOLDER + '/*.xml' ] ]