Appendix A. OGNL expressions

Although OGNL expressions are widely used in QuickBuild, generally, you do not need to know anything about OGNL because QuickBuild's user interface hides most of the OGNL expressions. For most properties that need an OGNL expression, you can choose from drop down menu. However, knowledge of OGNL expressions will give you an ability to set up very complicated and powerfull configurations. You can learn about OGNL at http://www.ognl.org, which is the official site for OGNL. This chapter assumes that you have some knowledge of OGNL, and it will concentrate on the properties and methods that can be used in QuickBuild.

Generally, there are two types of OGNL in QuickBuild. The first one is for boolean type properties, including Build necessary condition, Step necessary condition, Build success condition, Step success condition, etc. These properties expect an OGNL expression that will be evaluated to a boolean value. The second one is for string type properties. Inside this string, any number of OGNL expressions can be embedded as long as they are embedded with ${...} expression. QuickBuild expects that they evaluate to a value of type string. Strings outside of ${...} expression will simply keep the same value during the evaluation. Every string-typed property in QuickBuild accepts OGNL expressions embedded within ${...} expression as long as it is not stated otherwise. Please note that double back slashes should be used for windows path in an OGNL expression, for example, ${"c:\\program files\\apache-ant-1.6.5\\bin\\ant.bat"}. Further more, if you assign Windows path as value of a variable, and refer to that variable in an OGNL expression, then that Windows path should also use double back slashes. For example, in order to assign Windows path of an ant executable to the variable pathToAnt, you may need to define it as:

pathToAnt = "c:\\program files\\apache-ant-1.6.5\\bin\\ant.bat"

The path is quoted because there are spaces inside it.

Every OGNL expression needs a root object in order to perform the evaluation. In QuickBuild, the root object is always the current configuration object. From this configuration object, you can access its exposed methods or properties, such as name, status, variables, repositories, builders, steps, the current build, the current object, etc. Once you get a stuff out of the configuration object, you can recursively get the other properties or methods exposed by that particular property. The definitive guide of these exposed methods or properties is the QuickBuild's JavaDoc. There are lots of methods and/or properties in the JavaDoc, you should only pay attention to methods or properties with OGNL: at the very beginning of the comment. Here are some typical OGNL expressions:

Get the build object that is running

build

Get the version of the build object that is running

build.version

Get the last build object

lastBuild

Get the last successful build object

lastSuccessBuild

Determine if the last build is successful

lastBuild.successful

Determine if the last build has failed

lastBuild.failed

Determine if the last build is running

lastBuild.running

Determine if the contents of the repository "cvs1" have been modified since the last build

repository["cvs1"].modified

Get the source path of the first module of the repository "svn1"

repository["svn1"].modules.get(0).srcPath

Get the head revision number of the repository "svn1"

repository["svn1"].headRevision

Get the workspace directory of the repository "accurev1" for the current build

repository["accurev1"].getWorkspaceDir(build)

Get the version of the remote build used by a QuickBuild repository

repository["quickbuild1"].remoteBuild.version

Determine if the contents of all used repositories have been modified since the last build

effectingRepositoriesModified

Determine if the contents of the repository "cvs1" have been modified since last successful build

lastSuccessBuild==null or repository["cvs1"].isModifiedSince(lastSuccessBuild)

Get the string value of variable "var1"

var["var1"]

Get the value of variable "var1" as integer

var["var1"].intValue

Increase the value of the variable "var1" as integer

var["var1"].increaseAsInt()

Set the value of the variable "var1" as "value1"

var["var1"].setValue("value1")

Increase the value of the variable "var1" as integer, and get the increased result

var["var1"].(increaseAsInt(), value)

Determine if the value of the variable "var1" equals "true"

var["var1"].value=="true"

Get the working directory of the current configuration

workingDir

Determine if the execution of the specified command is successful

system.execute("/path/to/my/command") == 0

Get the current hour

system.calendar.hour

Get the day of week

system.calendar.dayOfWeek

Determine if the execution of the step "step1" is successful

step["step1"].successful