Jenkinsfile.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 27 May 2016 23:09:29 +0100
changeset 20 0b7a237a445b
parent 5 0e2993dac13e
child 24 ae6fc15070e4
permissions -rwxr-xr-x
Fixed `Jenkinsfile.rb` to correctly propagate --project and --arch to `rake` Since `Jenkinsfile.rb` does not spawn a subprocess but rather executes rake within the same process, PROJECT and ARCH must be defined as Ruby constants rather than as plain environment variables.

#!/usr/bin/ruby
DOCUMENTATION = <<DOCEND
A help script to build a Smalltalk/X jv-branch (mainly) on a Jenkins CI. 

DOCEND

require 'optparse'

def run()
  optparse = OptionParser.new do | opts |
    opts.banner = "Usage: #{$0} [TASK1 [TASK2 [...]]\n"
    opts.on('-p', '--project PROJECT', "PROJECT to build. Overrides project specified by the environment variable.") do | value |
      ENV['PROJECT'] = value
      self.class.const_set('PROJECT', value)  
    end

    opts.on('-a', '--arch ARCH', "Arcitecture to build for. Overrides project specified by the environment variable.") do | value |
      ENV['ARCH'] = value
      self.class.const_set('ARCH', value)  
    end

    opts.on(nil, '--help', "Prints this message") do
      puts DOCUMENTATION
      puts optparse.help()
      exit 0
    end
  end

  optparse.parse!

  # If run outside a Jenkins build environment (such as from a command line), 
  # define some variables to make it look more like a proper  Jenkins build 
  # environment. 
  ENV['WORKSPACE'] ||= '.'
  ENV['BUILD_NUMBER'] ||= Time.now.strftime("%Y%m%d")
  ENV['JOB_NAME'] ||= 'interactive'
  
  # When run under Jenkins, we do want to see full backtrace if something
  # fails. 
  ARGV << '--trace'

  require 'rake'
  Rake.application.run
end

run if __FILE__ == $0