Jenkinsfile.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 30 May 2016 23:05:25 +0100
changeset 24 ae6fc15070e4
parent 20 0b7a237a445b
child 25 7ef6e0216e9c
permissions -rwxr-xr-x
Jenkinsfile.rb: added new target `jenkins:job` ...run when no targets are given to `Jenkinsfile.rb` on command line. This job does everything - checks out & updates existing code, (re)compiles, run tests and static analysis and finally create build artifacts.

#!/usr/bin/ruby
DOCUMENTATION = <<DOCEND
A help script to build a Smalltalk/X jv-branch (mainly) on a Jenkins CI. 
If no TARGET is given, invokes target `jenkins:job`.

DOCEND

require 'optparse'

def run()
  optparse = OptionParser.new do | opts |
    opts.banner = "Usage: #{$0} [TARGET1 [TARGET1 [...]]\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'

  # If no target is given, run target jenkins:job
  if ARGV.size == 0 then
    ARGV << 'jenkins:job'
  end
  
  # 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