diff options
author | Memphiz <memphis@machzwo.de> | 2013-08-22 23:50:28 +0200 |
---|---|---|
committer | Memphiz <memphis@machzwo.de> | 2013-08-22 23:50:28 +0200 |
commit | 32bfe5162527f76057779575f011ab95436ae70a (patch) | |
tree | b9341f20cd5517ac4f59dcbb9242cac30a3f3866 /tools/buildsteps/defaultenv | |
parent | e276ddf16e851acb7adffaa5726cc6aa28969f5b (diff) |
[jenkins] - fixed approach for detecting the current branch once and for all (works for attached and detached heads and also for pull requests)
Diffstat (limited to 'tools/buildsteps/defaultenv')
-rw-r--r-- | tools/buildsteps/defaultenv | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tools/buildsteps/defaultenv b/tools/buildsteps/defaultenv index 93d3c13148..5d7514928f 100644 --- a/tools/buildsteps/defaultenv +++ b/tools/buildsteps/defaultenv @@ -111,6 +111,31 @@ function tagSuccessFulBuild () echo "$(getBuildHash $checkPath)" > $checkPath/$PATH_CHANGE_REV_FILENAME } +function getBranchName () +{ + local branchName + branchName=`git symbolic-ref HEAD 2>/dev/null || echo detached` + + if [ "$branchName" != "detached" ] # if we are not detached + then + #we are attached - use the branchname then + if echo $branchName | grep pr 2>&1 > /dev/null + then + #if this is a pull request branch - fetch the pr number and prefix with "PR" + #refs/heads/number/head + echo PR$(echo $branchName | awk '{gsub(".*/pr/","");print $1}' | awk '{gsub("/.*","");print $1}') + else + #if we are on a normal branch - fetch branchname + #refs/heads/branchname + echo $branchName | awk '{gsub(".*/","");print $1}' + fi + else + #if we are in detached head state + #fetch the first non-pullrequest branch we can find with HEAD + git branch -r --contains HEAD | sed "/origin\/pr\//d" | head -n1 | awk '{gsub(".*/","");print $1}' + fi +} + function getBuildRevDateStr () { local revStr @@ -119,7 +144,7 @@ function getBuildRevDateStr () if [ "$?" == "0" ] then #fetch the first branch containing head - revStr=$revStr"-"`git branch -r --contains HEAD | sed "/origin\/pr\//d" | head -n1 | awk '{gsub(".*/","");print $1}'` + revStr=$revStr"-"$(getBranchName) if [ "$?" == "0" ] then echo $revStr |