How do I configure Jenkins to strip the leading "origin/" in git branch parameter? How do I configure Jenkins to strip the leading "origin/" in git branch parameter? jenkins jenkins

How do I configure Jenkins to strip the leading "origin/" in git branch parameter?


For the git branch parameter, set Branch Filter to:

origin/(.*)

I found the parentheses to be counter-intuitive, because if you don't specify a filter you get:

.*

(No parens.) If you are filtering stuff out, you use parens to indicate the part to keep.


If you need to filter multiple patterns without origin/ section, try the following.

origin/(develop.*|feature.*|bugfix.*)

This will list the develop, feature and bugfix branches without the leading origin/.


I usually use a groovy script evaluated before the job, like:

def map = [:]map['GIT_BRANCH'] = GIT_BRANCH - 'origin/'return map

This is using the EnvInject plugin, as described in gitlab-plugin issue 444