Dashboard > Pulse v2.0 > ... > Cookbook > CB - Custom artifact handling with post build hooks
  Pulse v2.0 Log In | Sign Up   View a printable version of the current page.  
  CB - Custom artifact handling with post build hooks
Added by Jason Sankey, last edited by Jason Sankey on Nov 20, 2008  (view change)
Labels: 
(None)

Pulse Manual Index

Introduction

As part of a build, pulse™ is able to capture build artifacts, files (or whole directories) produced during the build. These artifacts may include compiled libraries and binaries, test reports etc. In some cases, you may wish to perform extra processing on these files at the end of the build. One possibility is to add a new target to your build script, and invoke that target at the end of the build. Alternatively, you can use a run executable task run from a post build hook to invoke a custom script to do the processing for you.

In this article, we take the case where you would like to copy build artifacts to some fixed directory after every success build. We will illustrate how this can be achieved by using a post build hook to invoke a simple bash script.

Example Project

To keep this article simple, we will assume a simple project setup. Our example project has a single build stage named "default" (like the one pulse™ creates for you when a project is added). This stage executes a recipe with a single command named "build". As part of the build, a directory of library files is created and captured as a directory artifact named "libraries".

The goal of the post build hook is to copy this library files to a destination directory of "/mnt/shared/lib". The libraries should only be copied when the build is succesful.

Bash Script

To perform the copying operation, we use a simple bash script which we will call "publish.sh". The script takes a single argument: the path of the directory to copy the library files from. It contains a simple copy operation:

publish.sh
#! /usr/bin/env bash

set -e

DEST=/mnt/share/lib

if [[ $# -ne 1 ]]
then
    echo "Usage: $0 <src dir>"
     exit 1
fi

rm -f "$DEST"/*
cp "$1"/* "$DEST"

exit 0

For easy access, we add publish.sh to /usr/local/bin.

Adding the Post Build Hook

To configure the post build action, we go to the configuration view for the project. Selecting the "build hooks" tree item shows a table of current hooks. Clicking the "add" link takes us to the build hook wizard. We fill in the wizard as follows:

  1. Select the "post build hook" hook type.
  2. Name the hook "publish", uncheck "run for all builds" and select "success" for the build states. Leave "fail on error" unchecked.
  3. Choose the "run executable task" task type.
  4. Set the command to "/usr/local/bin/publish.sh", and the arguments to "${stage.default.command.build.dir}/libraries".

Most of these values are straightforward. Notice that in the command arguments several variables are available, as listed on the Properties and Project Build Hooks pages. We use one that points us to the storage location for the build command, which allows us to access the artifacts we need. You can peek into this directory to see how things are stored by pulse™.

Further Information

For more information, see the following pages:

Zutubi wiki is Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators