#!/usr/bin/groovy @Library('jenkins-pipeline@v0.4.5') import com.invoca.docker.*; pipeline { agent { kubernetes { defaultContainer "ruby" yamlFile ".jenkins/ruby_build_pod.yml" } } environment { GITHUB_TOKEN = credentials('github_token') GITHUB_KEY = credentials('github_key') BUNDLE_GEM__FURY__IO = credentials('gemfury_deploy_token') } stages { stage('Setup') { steps { script { updateGitHubStatus('clean-build', 'pending', 'Unit tests.') sh ''' # get SSH setup inside the container eval `ssh-agent -s` echo "$GITHUB_KEY" | ssh-add - mkdir -p /root/.ssh ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts bundle install bundle exec appraisal install ''' } } } stage('Appraisals') { parallel { stage('Current') { environment { JUNIT_OUTPUT = 'spec/reports/current' } steps { sh "bundle exec rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml" } post { always { junit "${JUNIT_OUTPUT}/*.xml" } } } stage('Rails 4') { environment { JUNIT_OUTPUT = 'spec/reports/rails-4' } steps { sh "bundle exec appraisal rails-4 rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml" } post { always { junit "${JUNIT_OUTPUT}/*.xml" } } } stage('Rails 5') { environment { JUNIT_OUTPUT = 'spec/reports/rails-5' } steps { sh "bundle exec appraisal rails-5 rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml" } post { always { junit "${JUNIT_OUTPUT}/*.xml" } } } stage('Rails 6') { environment { JUNIT_OUTPUT = 'spec/reports/rails-6' } steps { sh "bundle exec appraisal rails-6 rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml" } post { always { junit "${JUNIT_OUTPUT}/*.xml" } } } } post { success { updateGitHubStatus('clean-build', 'success', 'Unit tests.') } failure { updateGitHubStatus('clean-build', 'failure', 'Unit tests.') } } } } } void updateGitHubStatus(String context, String status, String description) { gitHubStatus([ repoSlug: 'Invoca/exception_handling', sha: env.GIT_COMMIT, description: description, context: context, targetURL: env.RUN_DISPLAY_URL, token: env.GITHUB_TOKEN, status: status ]) }