Searching around the forum, I couldn't find anyone else having reported this, so I thought I'd post it in case anyone else finds it useful. We work from a Subversion repository, and one request we had was to be able to have a drop-down list of available SVN tags when a build is triggered. A bit of MVEL scripting later, and I've managed to make it happen. Each time a build is triggered, the Specify Build Options screen presents you with a list of choices. Getting this to work required a bit of configuration, but it seems to work well and has made our developers happy.
The scripts below assume a few things about variables that are configured:
[list]
svn_password - password to match. Note that the script will currently fail if any shell-significant characters are in the password.[/*:m]
buildInstance - One of "dev", "qa", "prod", etc. Script assumes 'trunk' should be disallowed for PROD builds.[/*:m][/list:u]
These scripts also assume you're using the standard SVN "trinity" layout of branches, tags, and trunk all in a single parent path.
You need a Subversion repository object. We'll assume it's called "SVN". The following attributes should be set:
[list]
Url to label as: https://example.org/svn/tags/{0}[/*:m]
[*]Plus username, password, and anything else you need of course.[/*:m][/list:u]
At a shared top-level configuration, define the following variables:
svn_tag_name: prompt as selection box. Set the choices script to the following:
${
repo = repositories.get("SVN");
if(repo instanceof com.pmease.quickbuild.plugin.scm.svn.SvnRepository) {
// It's SVN. Let's get a list of tags.
// Start with the label URL and trim off any tags/branches/trunk on the end.
sUrl = repo.getLabelUrl();
sUrl = sUrl.replaceAll("^(.*)/(?:branches/.*|tags/.*|trunk)/?$", "$1/tags/");
// Call SVN binary to get a list (one per line w/ a trailing slash)
sTags = util.readOutput(vars.get("svn_path") + "/svn" +
" --username " + vars.get("svn_username") +
" --password " + vars.get("svn_password") +
" list " + sUrl);
// Regex to cut off the trailing slashes.
pat = java.util.regex.Pattern.compile("^(.*)/$", java.util.regex.Pattern.MULTILINE);
mat = pat.matcher(sTags);
sTags = mat.replaceAll("$1");
if(vars.getValue("buildInstance").toLowerCase() != "prod") {
// Add a trunk option if we're not in prod.
sTags = "trunk\n" + sTags;
\}
return sTags;
\}
return "";
}
svn_tag: do not prompt. Set the value script to the following:
${
if(vars.get("svn_tag_name").isEmpty() || vars.getValue("svn_tag_name") == "trunk") {
return "trunk";
\} else {
return "tags/" + vars.get("svn_tag");
\}
}
Assuming you have sub-configurations for dev, qa, prod, etc., you might wish to override the 'svn_tag_name' variable in the dev configuration and set it to 'trunk'. That way dev will always build the latest without prompting.
Best regards,
Zac Bedell