Jakub Josef | 25c0ea5 | 2017-04-27 17:46:27 +0200 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * Ruby functions |
| 5 | */ |
| 6 | |
Jakub Josef | ad59b2f | 2017-04-28 16:08:40 +0200 | [diff] [blame] | 7 | /** |
| 8 | * Ensures Ruby environment with given version (install it if necessary) |
| 9 | * @param rubyVersion target ruby version (optional, default 2.3.2) |
| 10 | */ |
| 11 | def ensureRubyEnv(rubyVersion="2.3.2"){ |
| 12 | if(!fileExists("/var/lib/jenkins/.rbenv/versions/${rubyVersion}/bin/ruby")){ |
| 13 | sh "rbenv install ${rubyVersion}"; |
| 14 | } |
| 15 | sh "rbenv local ${rubyVersion};rbenv exec gem update --system" |
Jakub Josef | 25c0ea5 | 2017-04-27 17:46:27 +0200 | [diff] [blame] | 16 | } |
Jakub Josef | ad59b2f | 2017-04-28 16:08:40 +0200 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Install kitchen tools |
| 20 | */ |
Jakub Josef | 25c0ea5 | 2017-04-27 17:46:27 +0200 | [diff] [blame] | 21 | def installKitchen(){ |
| 22 | sh """rbenv exec gem install bundler; |
Jakub Josef | 4cda59e | 2017-04-28 21:00:01 +0200 | [diff] [blame^] | 23 | rbenv exec gem install test-kitchen;""" |
| 24 | sh """ test -e Gemfile || cat <<EOF > Gemfile |
| 25 | source 'https://rubygems.org' |
| 26 | gem 'rake' |
| 27 | gem 'test-kitchen' |
| 28 | gem 'kitchen-docker' |
| 29 | gem 'kitchen-inspec' |
| 30 | gem 'inspec' |
| 31 | gem 'kitchen-salt', :git => 'https://github.com/epcim/kitchen-salt.git', :branch => 'dependencis-pkg-repo2' |
| 32 | #Waiting for PR#78 |
| 33 | #gem 'kitchen-salt', '>=0.2.25'""" |
| 34 | sh "rbenv exec bundler install --path vendor/bundle" |
Jakub Josef | 25c0ea5 | 2017-04-27 17:46:27 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Jakub Josef | ad59b2f | 2017-04-28 16:08:40 +0200 | [diff] [blame] | 37 | /** |
| 38 | * Run kitchen tests in tests/integration |
| 39 | */ |
Jakub Josef | 25c0ea5 | 2017-04-27 17:46:27 +0200 | [diff] [blame] | 40 | def runKitchenTests(){ |
| 41 | runKitchenCommand("converge") |
| 42 | runKitchenCommand("verify -t tests/integration") |
| 43 | } |
| 44 | |
Jakub Josef | ad59b2f | 2017-04-28 16:08:40 +0200 | [diff] [blame] | 45 | /** |
| 46 | * Run kitchen command |
| 47 | * @param cmd kitchen command |
| 48 | */ |
Jakub Josef | 25c0ea5 | 2017-04-27 17:46:27 +0200 | [diff] [blame] | 49 | def runKitchenCommand(cmd){ |
| 50 | sh "rbenv exec bundler exec kitchen ${cmd}" |
| 51 | } |
| 52 | |
| 53 | |
| 54 | |