Build Cleanly or Incrementally

Situation

For scheduled builds, run them incrementally. However if it is manually triggered, user needs to control whether it is a clean build or an incremental build.

Demonstration

Visit the demo project, click run button to trigger the build, and the build option screen will present a clean option. QuickBuild will clean up the workspace directory (and this means a clean build for this demo project) before running the build if this option is checked.

Resolution

  1. Define a variable clean in basic setting of the demo project, with prompt setting defined as a checkbox. The default value is set to false indicating all scheduled builds being incrementally. Note that variable name is arbitrary as long as the same name is referenced later.
  2. Switch to steps view of the demo project. This project defines the clean behavior to be workspace cleanup before running the build, and pre-execute script of the master step is defined as below to achieve this purpose:
    if (vars.get("clean").asBoolean())
      util.cleanDir(configuration.workspaceDir);
    

    If build is triggered by scheduler, default value of the variable will be used, which is false, and workspace directory will not cleaned. If triggered manually, the variable value will be either true or false depending on whether or not the user has checked the clean option.

This demo treats clean build as cleaning up the workspace directory before running the build. However, your clean build might have a different behavior, for example, cleaning up a sub directory under the workspace before running master step, or even deleting certain files before running certain steps. All of these logic can be customized using the pre-execute script and post-execute script of various steps. You may even use multiple variables to control the clean behavior.

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.