Undefined Title

Undefined Title

Environtment variables for jenkins when script running

Jenkins is great and useful as a general job scheduler. In cofiguration pane, you can configure shell script runs and scheduling like cron. Then you can use some environment variables.

For example, $BUILD_NUMBER provides the number of build and $WORKSPACE gives the workspace directory of the job.

[[ -z "$BUILD_NUMBER" ]] && suffix=`date +%Y%m%d-%H%M%S`

do_sth() {
  echo "..."
if ! do_sth; then
  exit 1

mkdir sth-$suffix

If this script runs on a jenkins job, it creates a directory with each build number in the workspace every build, otherwise it creates a directory with timestamp in $HOME. And it also sends a notification mail to you if the script is failed.