|
| 1 | +def initializeEnvironment() { |
| 2 | + |
| 3 | + env.DRIVER_DISPLAY_NAME = 'Cassandra Ruby Driver' |
| 4 | + env.DRIVER_METRIC_TYPE = 'oss' |
| 5 | + |
| 6 | + env.GIT_SHA = "${env.GIT_COMMIT.take(7)}" |
| 7 | + env.GITHUB_PROJECT_URL = "https://${GIT_URL.replaceFirst(/(git@|http:\/\/|https:\/\/)/, '').replace(':', '/').replace('.git', '')}" |
| 8 | + env.GITHUB_BRANCH_URL = "${GITHUB_PROJECT_URL}/tree/${env.BRANCH_NAME}" |
| 9 | + env.GITHUB_COMMIT_URL = "${GITHUB_PROJECT_URL}/commit/${env.GIT_COMMIT}" |
| 10 | + |
| 11 | + sh label: 'Download Apache CassandraⓇ or DataStax Enterprise', script: '''#!/bin/bash -lex |
| 12 | + . ${CCM_ENVIRONMENT_SHELL} ${CASSANDRA_VERSION} |
| 13 | + ''' |
| 14 | +} |
| 15 | + |
| 16 | +def installDependencies() { |
| 17 | + sh label: 'Set Ruby env and update gems', script: '''#!/bin/bash -le |
| 18 | + rbenv global ${RUBY_VERSION} |
| 19 | +
|
| 20 | + ruby_bin_version=`ruby -v` |
| 21 | + echo "Ruby binary version: ${ruby_bin_version}" |
| 22 | + if [[ $ruby_bin_version == jruby* ]]; then |
| 23 | + # Add '-java' to version as that is included in version name when using jruby |
| 24 | + echo "JRuby detected, updating Gemfile.lock" |
| 25 | + sed -i -r 's/cassandra-driver \\((.*)\\)/cassandra-driver (\\1-java)/' Gemfile.lock |
| 26 | + fi |
| 27 | +
|
| 28 | + bundle update --bundler |
| 29 | + bundle --version |
| 30 | + bundle install --without development docs |
| 31 | + ''' |
| 32 | +} |
| 33 | + |
| 34 | +def executeTests() { |
| 35 | + sh label: 'Execute all tests', script: '''#!/bin/bash -le |
| 36 | + # Load CCM environment variables |
| 37 | + set -o allexport |
| 38 | + . ${HOME}/environment.txt |
| 39 | + set +o allexport |
| 40 | +
|
| 41 | + bundle exec rake test |
| 42 | + ''' |
| 43 | +} |
| 44 | + |
| 45 | +pipeline { |
| 46 | + agent none |
| 47 | + |
| 48 | + // Global pipeline timeout |
| 49 | + options { |
| 50 | + timeout(time: 10, unit: 'HOURS') |
| 51 | + buildDiscarder(logRotator(artifactNumToKeepStr: '10', // Keep only the last 10 artifacts |
| 52 | + numToKeepStr: '50')) // Keep only the last 50 build records |
| 53 | + } |
| 54 | + |
| 55 | + environment { |
| 56 | + CCM_ENVIRONMENT_SHELL = '/usr/local/bin/ccm_environment.sh' |
| 57 | + } |
| 58 | + |
| 59 | + stages { |
| 60 | + stage('Per-Commit') { |
| 61 | + environment { |
| 62 | + OS_VERSION = 'ubuntu/bionic64/ruby-driver' |
| 63 | + } |
| 64 | + |
| 65 | + matrix { |
| 66 | + axes { |
| 67 | + axis { |
| 68 | + name 'CASSANDRA_VERSION' |
| 69 | + values '2.1', '3.11', '4.0' |
| 70 | + } |
| 71 | + axis { |
| 72 | + name 'RUBY_VERSION' |
| 73 | + values '2.3.6', '2.4.3', '2.7.0', 'jruby-9.1.15.0' |
| 74 | + } |
| 75 | + } |
| 76 | + agent { |
| 77 | + label "${OS_VERSION}" |
| 78 | + } |
| 79 | + |
| 80 | + stages { |
| 81 | + stage('Initialize-Environment') { |
| 82 | + steps { |
| 83 | + initializeEnvironment() |
| 84 | + } |
| 85 | + } |
| 86 | + stage('Install-Dependencies') { |
| 87 | + steps { |
| 88 | + installDependencies() |
| 89 | + } |
| 90 | + } |
| 91 | + stage('Execute-Tests') { |
| 92 | + steps { |
| 93 | + executeTests() |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments