I'm looking for a part-time remote job.

Hire me


I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).


Follow me:

Custom scripts

Since version 0.3.0 the plugin supports custom shell scripts which can be executed when a repository is created and when a repository is deleted. One can use these scripts to set permissions after a repository has been created, to archive a repository before it gets removed etc.

Script types

Scripts (pathes to them) must be specified in the configuration file scm.yml:

production:
  pre_create: /usr/local/bin/pre-create.sh
  post_create: /usr/local/bin/post-create.sh
  pre_delete: /usr/local/bin/pre-delete.sh
  post_delete: /usr/local/bin/post-delete.sh

pre_ scripts get executed before an action (before creation or before deletion). And post_ scripts get called after an action (after creation or after deletion).

In most cases you will want to use post_create and/or pre_delete scripts.

Arguments

All scripts are called with the following arguments:

  1. Path to the repository root (e.g. /var/lib/svn/project);
  2. Repository type (e.g. svn);
  3. Project identifier (e.g. scm-creator).

Possible values1 for the second argument (repository type):

  • svn - for Subversion;
  • git - for Git;
  • mercurial - for Mercurial;
  • bazaar - for Bazaar.
  • github - for Github.

Custom fields

You can use custom fields to pass aditional parameters to scripts.

Project custom fields (if their values are set, of course) are automatically made availabe to scripts as environment variables. The name of such environment variable begins with SCM_CUSTOM_FIELD_. The rest is formed from the custom field name. For example, custom field "Project type" will be available as SCM_CUSTOM_FIELD_PROJECT_TYPE.

Note: The environment variable name is obtained by replacing all non-latin characters, non-numbers and non-underscore by _.

Sample script

This is a skeleton which can be used as a template for scripts:

#!/bin/sh

SCM_REPO_PATH=$1
SCM_TYPE=$2
SCM_PROJECT=$3

SCM_REPO_NAME=$(basename $SCM_REPO_PATH)
SCM_REPO_ROOT=$(dirname $SCM_REPO_PATH)

case "$SCM_TYPE" in
    svn)
        ;;
    git)
        ;;
    mercurial)
        ;;
    bazaar)
        ;;
    github)
        ;;
    *)
        echo "SCM not supported: $SCM_TYPE" >&2
        ;;
esac

exit 0

1 this is actually a list of currently supported SCMs

template.sh Magnifier - Template script (326 Bytes) Andriy Lesyuk, 13 Nov 2011 17:53

Terms of use | Privacy policy