#!groovy def initializeEnvironment() { def nodeVersions = ['16': '16.20.2', '18': '18.17.1', '20': '20.5.1'] env.DRIVER_DISPLAY_NAME = 'Cassandra Node.js Driver' env.DRIVER_METRIC_TYPE = 'oss' if (env.GIT_URL.contains('riptano/nodejs-driver')) { env.DRIVER_DISPLAY_NAME = 'private ' + env.DRIVER_DISPLAY_NAME env.DRIVER_METRIC_TYPE = 'oss-private' } else if (env.GIT_URL.contains('nodejs-dse-driver')) { env.DRIVER_DISPLAY_NAME = 'DSE Node.js Driver' env.DRIVER_METRIC_TYPE = 'dse' } env.GIT_SHA = "${env.GIT_COMMIT.take(7)}" env.GITHUB_PROJECT_URL = "https://${GIT_URL.replaceFirst(/(git@|http:\/\/|https:\/\/)/, '').replace(':', '/').replace('.git', '')}" env.GITHUB_BRANCH_URL = "${GITHUB_PROJECT_URL}/tree/${env.BRANCH_NAME}" env.GITHUB_COMMIT_URL = "${GITHUB_PROJECT_URL}/commit/${env.GIT_COMMIT}" env.NODEJS_VERSION_FULL = nodeVersions[env.NODEJS_VERSION] sh label: 'Assign Node.js global environment', script: '''#!/bin/bash -lex nodenv versions echo "Using Node.js runtime ${NODEJS_VERSION} (${NODEJS_VERSION_FULL})" nodenv global ${NODEJS_VERSION_FULL} ''' sh label: 'Download Apache Cassandra or DataStax Enterprise', script: '''#!/bin/bash -lex . ${CCM_ENVIRONMENT_SHELL} ${CASSANDRA_VERSION} ''' if (env.CASSANDRA_VERSION.split('-')[0] == 'dse') { env.DSE_FIXED_VERSION = env.CASSANDRA_VERSION.split('-')[1] sh label: 'Update environment for DataStax Enterprise', script: '''#!/bin/bash -le cat >> ${HOME}/environment.txt << ENVIRONMENT_EOF CCM_PATH=${HOME}/ccm CCM_CASSANDRA_VERSION=${DSE_FIXED_VERSION} # maintain for backwards compatibility CCM_VERSION=${DSE_FIXED_VERSION} CCM_SERVER_TYPE=dse DSE_VERSION=${DSE_FIXED_VERSION} CCM_IS_DSE=true CCM_BRANCH=${DSE_FIXED_VERSION} DSE_BRANCH=${DSE_FIXED_VERSION} ENVIRONMENT_EOF ''' } sh label: 'Display Node.js and environment information', script: '''#!/bin/bash -le # Load CCM environment variables set -o allexport . ${HOME}/environment.txt set +o allexport node --version npm --version printenv | sort ''' } def installDriverAndDependencies() { sh label: 'Install the driver', script: '''#!/bin/bash -lex npm install ''' sh label: 'Install driver dependencies', script: '''#!/bin/bash -lex npm install mocha-jenkins-reporter@0 npm install kerberos@1 npm install -g eslint@4 ''' } def executeLinter() { sh label: 'Perform static analysis of source code', script: '''#!/bin/bash -lex npm run eslint ''' } def executeTests() { sh label: 'Execute tests', script: '''#!/bin/bash -lex # Load CCM environment variables set -o allexport . ${HOME}/environment.txt set +o allexport npm run ci_jenkins ''' } def executeExamples() { sh label: 'Create CCM cluster for examples', script: '''#!/bin/bash -lex # Load CCM environment variables set -o allexport . ${HOME}/environment.txt set +o allexport ccm create test_samples --dse -v ${CCM_VERSION} -n 1:0 -b -s ''' sh label: 'Execute examples', script: '''#!/bin/bash -lex set -o allexport . ${HOME}/environment.txt set +o allexport ( cd examples npm install node runner.js ) ''' sh label: 'Clean-up CCM cluster for examples', script: '''#!/bin/bash -lex ccm remove ''' } def notifySlack(status = 'started') { // Set the global pipeline scoped environment (this is above each matrix) env.BUILD_STATED_SLACK_NOTIFIED = 'true' def buildType = 'Commit' if (params.CI_SCHEDULE != 'DO-NOT-CHANGE-THIS-SELECTION') { buildType = "${params.CI_SCHEDULE.toLowerCase().capitalize()}" } def color = 'good' // Green if (status.equalsIgnoreCase('aborted')) { color = '808080' // Grey } else if (status.equalsIgnoreCase('unstable')) { color = 'warning' // Orange } else if (status.equalsIgnoreCase('failed')) { color = 'danger' // Red } def message = """Build ${status} for ${env.DRIVER_DISPLAY_NAME} [${buildType}] <${env.GITHUB_BRANCH_URL}|${env.BRANCH_NAME}> - <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> - <${env.GITHUB_COMMIT_URL}|${env.GIT_SHA}>""" if (!status.equalsIgnoreCase('Started')) { message += """ ${status} after ${currentBuild.durationString - ' and counting'}""" } slackSend color: "${color}", channel: "#nodejs-driver-dev-bots", message: "${message}" } def describePerCommitStage() { script { currentBuild.displayName = "Per-Commit" currentBuild.description = '''Per-Commit build and testing''' } } def describeScheduledTestingStage() { script { def type = params.CI_SCHEDULE.toLowerCase().capitalize() currentBuild.displayName = "${type} schedule" currentBuild.description = "${type} scheduled build and testing of all supported Apache Cassandra and DataStax " + "Enterprise against multiple Node.js runtimes" } } def describeAdhocTestingStage() { script { def serverType = params.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION.split('-')[0] def serverDisplayName = 'Apache Cassandra' def serverVersion = " v${serverType}" if (serverType == 'ALL') { serverDisplayName = "all ${serverDisplayName} and DataStax Enterprise server versions" serverVersion = '' } else { try { serverVersion = " v${env.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION.split('-')[1]}" } catch (e) { ;; // no-op } if (serverType == 'ddac') { serverDisplayName = "DataStax Distribution of ${serverDisplayName}" } else if (serverType == 'dse') { serverDisplayName = 'DataStax Enterprise' } } def nodeJsVersionInformation = "Node.js v${params.ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION}" if (params.ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION == 'ALL') { nodeJsVersionInformation = 'all Node.js versions' } def examplesInformation = '' if (ADHOC_BUILD_AND_EXECUTE_TESTS_EXECUTE_EXAMPLES) { examplesInformation = ' with examples' } currentBuild.displayName = "${params.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION} against ${nodeJsVersionInformation}" currentBuild.description = "Testing ${serverDisplayName} ${serverVersion} against ${nodeJsVersionInformation}${examplesInformation}" } } // branch pattern for cron def branchPatternCron() { ~"(master)" } pipeline { agent none // Global pipeline timeout options { disableConcurrentBuilds() timeout(time: 5, unit: 'HOURS') buildDiscarder(logRotator(artifactNumToKeepStr: '10', // Keep only the last 10 artifacts numToKeepStr: '50')) // Keep only the last 50 build records } parameters { choice( name: 'ADHOC_BUILD_TYPE', choices: ['BUILD', 'BUILD-AND-EXECUTE-TESTS'], description: '''

Perform a adhoc build operation

Choice Description
BUILD Performs a Per-Commit build
BUILD-AND-EXECUTE-TESTS Performs a build and executes the integration and unit tests
''') choice( name: 'ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION', choices: ['16', '18', '20', 'ALL'], description: 'Node.js version to use for adhoc BUILD-AND-EXECUTE-TESTS ONLY!') choice( name: 'ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION', choices: [ '3.11', // Current Apache Cassandra '4.0', // Development Apache Cassandra 'dse-5.1.35', // Legacy DataStax Enterprise 'dse-6.8.30', // Development DataStax Enterprise 'ALL'], description: '''Apache Cassandra and DataStax Enterprise server version to use for adhoc BUILD-AND-EXECUTE-TESTS ONLY!
Choice Description
3.11 Apache Cassandra v3.11.x
4.0 Apache Cassandra v4.x (CURRENTLY UNDER DEVELOPMENT)
dse-5.1 DataStax Enterprise v5.1.x
dse-6.8 DataStax Enterprise v6.8.x (CURRENTLY UNDER DEVELOPMENT)
''') booleanParam( name: 'ADHOC_BUILD_AND_EXECUTE_TESTS_EXECUTE_EXAMPLES', defaultValue: false, description: 'Flag to determine if the examples should be executed for adhoc builds') booleanParam( name: 'JUNIT_REPORT_STACK', defaultValue: true, description: 'Flag to determine if stack trace should be enabled with test failures for scheduled or adhoc builds') booleanParam( name: 'TEST_TRACE', defaultValue: true, description: 'Flag to determine if test tracing should be enabled for scheduled or adhoc builds') choice( name: 'CI_SCHEDULE', choices: ['DO-NOT-CHANGE-THIS-SELECTION', 'WEEKNIGHTS'], description: 'CI testing schedule to execute periodically scheduled builds and tests of the driver (DO NOT CHANGE THIS SELECTION)') } triggers { parameterizedCron(branchPatternCron().matcher(env.BRANCH_NAME).matches() ? """ # Every weeknight (Monday - Friday) around 7 PM H 19 * * 1-5 %CI_SCHEDULE=WEEKNIGHTS """ : "") } environment { OS_VERSION = 'ubuntu/jammy64/nodejs-driver' JUNIT_REPORT_STACK = "${params.JUNIT_REPORT_STACK ? '1' : '0'}" JUNIT_REPORT_PATH = '.' TEST_TRACE = "${params.TEST_TRACE ? 'on' : 'off'}" SIMULACRON_PATH = '/home/jenkins/simulacron.jar' CCM_PATH = '/home/jenkins/ccm' CCM_ENVIRONMENT_SHELL = '/usr/local/bin/ccm_environment.sh' } stages { stage('Per-Commit') { when { beforeAgent true allOf { expression { params.ADHOC_BUILD_TYPE == 'BUILD' } expression { params.CI_SCHEDULE == 'DO-NOT-CHANGE-THIS-SELECTION' } not { buildingTag() } } } matrix { axes { axis { name 'CASSANDRA_VERSION' values '3.11', // Current Apache Cassandra '4.0', // Development Apache Cassandra 'dse-5.1.35', // Legacy DataStax Enterprise 'dse-6.8.30' // Development DataStax Enterprise } axis { name 'NODEJS_VERSION' values '16', '18', '20' } } agent { label "${OS_VERSION}" } stages { stage('Initialize-Environment') { steps { initializeEnvironment() script { if (env.BUILD_STATED_SLACK_NOTIFIED != 'true') { notifySlack() } } } } stage('Describe-Build') { steps { describePerCommitStage() } } stage('Install-Driver-And-Dependencies') { steps { installDriverAndDependencies() } } stage('Execute-Linter') { steps { executeLinter() } } stage('Execute-Tests') { steps { catchError { // Handle error conditions in the event examples should be executed executeTests() } } post { always { junit testResults: '*.xml' } } } stage('Execute-Examples') { when { expression { env.CASSANDRA_VERSION == 'dse-6.8.30' } } steps { executeExamples() } } } } post { aborted { notifySlack('aborted') } success { notifySlack('completed') } unstable { notifySlack('unstable') } failure { notifySlack('FAILED') } } } stage('Scheduled-Testing') { when { beforeAgent true branch pattern: '((\\d+(\\.[\\dx]+)+)|dse|master)', comparator: 'REGEXP' allOf { expression { params.ADHOC_BUILD_TYPE == 'BUILD' } expression { params.CI_SCHEDULE != 'DO-NOT-CHANGE-THIS-SELECTION' } not { buildingTag() } } } matrix { axes { axis { name 'CASSANDRA_VERSION' values '3.11', // Current Apache Cassandra '4.0', // Development Apache Cassandra 'dse-5.1.35', // Legacy DataStax Enterprise 'dse-6.8.30' // Development DataStax Enterprise } axis { name 'NODEJS_VERSION' values '16', '18', '20' } } agent { label "${OS_VERSION}" } stages { stage('Initialize-Environment') { steps { initializeEnvironment() script { if (env.BUILD_STATED_SLACK_NOTIFIED != 'true') { notifySlack() } } } } stage('Describe-Build') { steps { describeScheduledTestingStage() } } stage('Install-Driver-And-Dependencies') { steps { installDriverAndDependencies() } } stage('Execute-Linter') { steps { executeLinter() } } stage('Execute-Tests') { steps { catchError { // Handle error conditions in the event examples should be executed executeTests() } } post { always { junit testResults: '*.xml' } } } stage('Execute-Examples') { when { expression { env.CASSANDRA_VERSION == 'dse-6.8.30' } } steps { executeExamples() } } } } post { aborted { notifySlack('aborted') } success { notifySlack('completed') } unstable { notifySlack('unstable') } failure { notifySlack('FAILED') } } } stage('Adhoc-Testing') { when { beforeAgent true allOf { expression { params.ADHOC_BUILD_TYPE == 'BUILD-AND-EXECUTE-TESTS' } not { buildingTag() } } } matrix { axes { axis { name 'CASSANDRA_VERSION' values '3.11', // Current Apache Cassandra '4.0', // Development Apache Cassandra 'dse-5.1.35', // Legacy DataStax Enterprise 'dse-6.8.30' // Development DataStax Enterprise } axis { name 'NODEJS_VERSION' values '16', '18', '20' } } when { beforeAgent true allOf { expression { params.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION ==~ /(ALL|${env.CASSANDRA_VERSION})/ } expression { params.ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION ==~ /(ALL|${env.NODEJS_VERSION})/ } } } agent { label "${OS_VERSION}" } stages { stage('Describe-Build') { steps { describeAdhocTestingStage() } } stage('Initialize-Environment') { steps { initializeEnvironment() } } stage('Install-Driver-And-Dependencies') { steps { installDriverAndDependencies() } } stage('Execute-Linter') { steps { executeLinter() } } stage('Execute-Tests') { steps { catchError { // Handle error conditions in the event examples should be executed executeTests() } } post { always { junit testResults: '*.xml' } } } stage('Execute-Examples') { when { expression { params.ADHOC_BUILD_AND_EXECUTE_TESTS_EXECUTE_EXAMPLES } } steps { executeExamples() } } } } } } }