In the job we are using parameter called BRANCH_NAME which is passed onto the plugin to clone and build the branch. Everything works fine, up to point that there is a build failure in any branch. After failure, the BRANCH_NAME requested to be build is ignored and the failed branch is always built.
How to reproduce the problem:
Create a simple job where you with parameter JOB_FAIL. Create a repository with few branches. Point the job to use the repository created. Build all the branches successfully. Once completed, build one branch with JOB_FAIL set true. After job failure, try building from a different branch and observe whether branch requested for the build is actually used.
In our tests, after failure, all other branches will use fail branch for the build rather than branch specified as parameter.
Potential work-around is to create a copy of the job and use it. Since copy doesn't have a build history, it uses branch requested through parameter.
Our job config.xml used for testing is attached.