-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
110 lines (101 loc) · 2.66 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
stage('Install dependencies') {
node {
checkout scm
withRvm('ruby-2.3.1') {
sh 'bundle -v || gem install bundler'
sh 'bundle install'
stash includes: 'Gemfile.lock, .bundle', name: 'bundle'
}
}
}
stage('Style checks') {
parallel(Rubocop: {
node {
checkout scm
withRvm('ruby-2.3.1') {
unstash 'bundle'
bundle_exec 'rake style:rubocop'
}
}
})
}
stage('Tests') {
parallel(Unit: {
node {
checkout scm
withRvm('ruby-2.3.1') {
unstash 'bundle'
bundle_exec 'rake spec:unit'
}
}
}, Integration: {
node {
checkout scm
withRvm('ruby-2.3.1') {
unstash 'bundle'
bundle_exec 'rake spec:integration'
}
}
}, System: {
node {
checkout scm
withRvm('ruby-2.3.1') {
unstash 'bundle'
bundle_exec 'rake spec:system'
}
}
})
}
if (isRelease()) {
stage('Publish') {
echo 'Would publish to rubygems.org' // TODO
slackSend "Published ${name()} gem version ${version()} to the rubygems.org", color: 'good'
}
}
def bundle_exec(command) {
sh "bundle exec ${command}"
}
def isRelease() {
false // FIXME: Building git tags is not yet supported (JENKINS-34395)
}
def name() {
node {
def matcher = readFile('packer-client.gemspec') =~ "spec.name += '(.+)'"
matcher ? matcher[0][1] : null
}
}
def version() {
node {
def matcher = readFile('lib/packer/version.rb') =~ "VERSION = '(.+)'"
matcher ? matcher[0][1] : null
}
}
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 "#!/bin/bash\nset +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"
]) {
cl()
}
}