Skip to content

Instantly share code, notes, and snippets.

@cdenneen
Last active July 23, 2018 00:55
Show Gist options
  • Save cdenneen/3f000d7f9a599534b8803593096f8cd1 to your computer and use it in GitHub Desktop.
Save cdenneen/3f000d7f9a599534b8803593096f8cd1 to your computer and use it in GitHub Desktop.
Jenkins Pipeline with matrix testing
node {
stage 'Checkout'
git branch: 'production', url: 'https://github.com/cdenneen/control-repo.git'
stash "${env.JOB_NAME}"
stage: 'Test'
gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
// short SHA, possibly better for chat notifications, etc.
shortCommit = gitCommit.take(6)
sh "echo $shortCommit"
def matrix = [:]
def rubyVersion = ['2.1.10', '2.3.3']
for (int x = 0; x < rubyVersion.size(); x++) {
def puppetVersion = ['4.7.1', '4.8.1', '4.9.4']
for (int i = 0; i < puppetVersion.size(); i++) {
RUBY_VERSION = rubyVersion[x]
PUPPET_GEM_VERSION = puppetVersion[i]
// matrix["version_r${rubyVersion[x]}_p${puppetVersion[i]}"] = {
withRvm("ruby-${RUBY_VERSION}") {
withEnv(["PUPPET_GEM_VERSION=${PUPPET_GEM_VERSION}"]) {
stage("ruby-${RUBY_VERSION} and puppet-${PUPPET_GEM_VERSION}") {
echo "$RUBY_VERSION + $PUPPET_GEM_VERSION"
}
stage("spec r${RUBY_VERSION}p${PUPPET_GEM_VERSION}") {
sh 'gem install bundler --no-ri --no-rdoc'
sh 'bundle install'
}
stage('Do Puppet Code Validation') {
sh 'bundle exec rake validate'
}
}
}
// }
}
}
// parallel matrix
}
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"]) {
withEnv(["PATH=$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"
]) {
'gem install bundler'
cl()
}
}
Started by user Jenkins
[Pipeline] node
Running on master in /var/jenkins_home/workspace/newtestrvm
[Pipeline] {
[Pipeline] stage (Checkout)
Using the ‘stage’ step without a block argument is deprecated
Entering stage Checkout
Proceeding
[Pipeline] git
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/cdenneen/control-repo.git # timeout=10
Fetching upstream changes from https://github.com/cdenneen/control-repo.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/cdenneen/control-repo.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/production^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/production^{commit} # timeout=10
Checking out Revision 2d0a4090863c173818fa546732d29b05108845be (refs/remotes/origin/production)
> git config core.sparsecheckout # timeout=10
> git checkout -f 2d0a4090863c173818fa546732d29b05108845be
> git branch -a -v --no-abbrev # timeout=10
> git branch -D production # timeout=10
> git checkout -b production 2d0a4090863c173818fa546732d29b05108845be
> git rev-list 2d0a4090863c173818fa546732d29b05108845be # timeout=10
[Pipeline] stash
Stashed 59 file(s)
[Pipeline] sh
[newtestrvm] Running shell script
+ git rev-parse HEAD
[Pipeline] sh
[newtestrvm] Running shell script
+ echo 2d0a40
2d0a40
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
[newtestrvm] Running shell script
+ set +x
Using /var/jenkins_home/.rvm/gems/ruby-2.1.10 with gemset executor-4
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (ruby-2.1.10 and puppet-4.7.1)
[Pipeline] echo
2.1.10 + 4.7.1
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (spec r2.1.10p4.7.1)
[Pipeline] sh
[newtestrvm] Running shell script
+ gem install bundler --no-ri --no-rdoc
/var/jenkins_home/workspace/newtestrvm@tmp/durable-c92c3934/script.sh: line 2: gem: command not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
@cdenneen
Copy link
Author

Rev 5 works... Rev 6 moving RUBY_VERSION and PUPPET_GEM_VERSION inside the matrix makes them return null

@cdenneen
Copy link
Author

Rev7 while it evaluates it's not matching the matrix... see lines 35-41 for example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment