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" post-build action 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 action 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 specification named "default" which has a single build stage also named "default" (like the one pulse™ creates for you when a project is added). This build specification 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 action 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:
#! /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 Action
To configure the post-build action, we go to the configuration tab for the project. Clicking "add new action" takes us to the post-build action wizard. We fill in the first page of the wizard as follows:
| Field |
Value |
Description |
| name |
publish |
A descriptive name, which can be anything you like. |
| type |
run executable |
The type of action to run: we wish to run our script. |
| apply to specifications |
default |
We select "default" so this action will only happen after builds of that specification. |
| resrict to states |
success |
We select "success" so the action will only happen after successful builds. |
| fail build on error |
unchecked |
We do not wish the script to affect the build state. |
On the next wizard page, we enter the details about the script we want to run:
| Field |
Value |
Description |
| command |
/usr/local/bin/publish.sh |
Path of the script to execute. |
| arguments |
"${stage.default.command.build.dir}/libraries" |
The variable will expand to the directory where the results of the command "build" in stage "default" are stored. Artifacts are stored underneath here in directories named after the artifact (hence the additional "/libraries"). |
Most of these values are straightforward. Notice that in the command arguments several variables are available. We use one that points us to the storage location for the build command, which allows us to access the artifacts we need. If there has been a previous successful build, example variables and values are shown on the post-build action configuration page. These illustrate the information available. You can also peek into the directories to see how things are stored by pulse™.
Further Information
For more information, see the following pages: