This repository has been archived by the owner on Jun 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
80 lines (70 loc) · 1.74 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
stage 'Checkout'
node {
checkout(scm)
stash 'source'
}
stage 'Tests'
parallel(
knapsack(2) {
node {
withCleanup {
unstash 'source'
withRvm('ruby-2.3.1') {
sh 'bundle install'
sh 'bundle exec rake knapsack:rspec'
}
}
}
}
)
def knapsack(ci_node_total, cl) {
def nodes = [:]
for(int i = 0; i < ci_node_total; i++) {
def index = i;
nodes["ci_node_${i}"] = {
withEnv(["CI_NODE_INDEX=$index", "CI_NODE_TOTAL=$ci_node_total"]) {
cl()
}
}
}
return nodes;
}
// Helper functions
def withCleanup(Closure cl) {
deleteDir()
try {
cl()
} finally {
deleteDir()
}
}
def withRvm(version, cl) {
withRvm(version, "executor-${env.EXECUTOR_NUMBER}") {
cl()
}
}
def withRvm(version, gemset, cl) {
RVM_HOME='$HOME/.rvm'
paths = [
"$RVM_HOME/gems/$version@$gemset/bin",
"$RVM_HOME/gems/$version@global/bin",
"$RVM_HOME/rubies/$version/bin",
"$RVM_HOME/bin",
"${env.PATH}"
]
def path = paths.join(':')
withEnv(["PATH=${env.PATH}:$RVM_HOME", "RVM_HOME=$RVM_HOME"]) {
sh "set +x; source $RVM_HOME/scripts/rvm; rvm use --create --install --binary $version@$gemset"
}
withEnv([
"PATH=$path",
"GEM_HOME=$RVM_HOME/gems/$version@$gemset",
"GEM_PATH=$RVM_HOME/gems/$version@$gemset:$RVM_HOME/gems/$version@global",
"MY_RUBY_HOME=$RVM_HOME/rubies/$version",
"IRBRC=$RVM_HOME/rubies/$version/.irbrc",
"RUBY_VERSION=$version"
]) {
sh 'gem install bundler'
cl()
}
}