If you have Oracle OSB 11.1.1.7.0 or higher this document will help you to automate the compilation process for OSB at project level.

Pre-requisites (what I have installed in my environment «for Linux it’s the same, just change the installers and use the <.sh> scripts instead <.bat> ones.»)

We won’t need OEPE to compile, but is a pre-requisite to install OSB which we need.

Manual execution of ConfigJar

After installing those components, you’ll find out a directory in your OSB home: {Oracle_OSB}\tools\configjar

There is a tool called «configjar.bat» which to work requires that you run first the «setenv.bat» you should see a directory like this:

configjar directory's content.

configjar directory’s content.

In order to use configjar, you’ll have to:

  • Run setenv.bat
  • Have a project or resource level xml of your project
  • Run configjar.bat with that xml

This is a project level xml example, this means we’ll generate a JAR for a whole project:

<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
    <source>
        <project dir="C:\Users\m.ortiz.montealegre\.babun\cygwin\home\m.ortiz.montealegre\repository\OSB\Front\MyProject"/>
    </source>
	
    <configjar jar="C:\deploy\MyProject.jar">
         <projectLevel includeSystem="false"/>
    </configjar>
	    
</configjarSettings>

If you want to generate OSB jars with your command line, project level, using ANT or even at resource level here’s the whole guide of Oracle and here are all the XML examples you may need.

In the previous xml example, we export one project with «no dependencies», in case you need to include dependencies then change «includeSystem» to «True».

Automating the process with Python and Jenkins

This is just a part of my main script to perform the compilation task but it serves as a good example.

Basically the script has a couple of variables to complete the paths for each OSB project. The script will create the xml files required for configjar.bat by redirecting the standard output to a file.

Finally the python script calls a sub-shell process to invoke the configjar.bat with the «-settingsfile» paramenter and the xml filename.

#!/usr/bin/python
# compilador osb
# miguel.ortiz

import os, sys, re, time, errno, subprocess

baseRepoDir = "C:/Users/m.ortiz.montealegre/.babun/cygwin/home/m.ortiz.montealegre/myrepo/" 
baseFront = '/OSB/Front/'

# compilarFront is a list of OSB projects which isn't incldued in this script for privacy reasons

for i in compilarFront :
        compilarFrontPath = baseRepoDir + baseFront + i
        f = open( jenkinsWorkspaceFront + i + ".xml", 'w')
        sys.stdout = f # Redirige la salida estandar a nuestro archivo
        print "<configjarSettings xmlns='http://www.bea.com/alsb/tools/configjar/config'>"
        print "<source>"
        print "<project dir='" + compilarFrontPath + "'/>"
        print "</source>"
        print "<configjar jar='" + OutputFrontJar + i + ".jar'>"
        print '<projectLevel includeSystem="false"/>'
        print '</configjar>'
        print '</configjarSettings>'
        sys.stdout = sys.__stdout__ # Regresa la salida estandar a su estado original
        f.close()
        mystdout = open( logDir + i + '_' + time.strftime("%Y%m%d-%H%M%S")  + '.log', 'w')
        subprocess.call([configJarTool + ' -settingsfile ' + jenkinsWorkspaceFront + i + '.xml'], stdout=mystdout, shell=True)
        print jenkinsWorkspaceFront+i+'.xml'

Because configjar.bat requires setenv.bat I modified the configjar.bat to call it:

@echo off
call C:\Oracle\Middleware\Oracle_OSB\tools\configjar\setenv.bat
"%JAVA_HOME%\bin\java" %JAVA_OPTS% com.bea.alsb.tools.configjar.ConfigJar %*

Setup in Jenkins

Once I was able to run the python script manually I just need to call the script in python and it will perform the compilation. Also I’ve added a parameterized option to pass the branch from which I want to compile:

And some GIT paramenters to fetch the branch of course.

Also I gave the project a defined workspace and an specific node to run improving the performance of this and other tasks in our Jenkins server:

Finally in the Build step of your project add an «Execute Windows Batch command»:

cd myproject
git fetch --all
git checkout origin/%RAMA_COMPILAR%
python G:\devops\compilacion\osb_compile.py