I have git repository on bitbucket server. Also have a Jenkins pipeline job that is pointed to that repository. From the pipeline it is possible to identify if a branch is a topic branch or a long-lived branch (I have specified a pattern for long lived branches). But I don't see any way to determine the source branch of a topic branch. I need to provide this source branch in order to run sonar analysis (sonar.target.branch parameter). To get this source branch I am using env.CHANGE_TARGET parameter in pipeline. But it is always null. I could also get source branch by running a git command. But it is not that accurate. So I need a robust way to identify target branch for a topic branch and better not having to run git commands. How do I achieve this ???
Asked
Active
Viewed 623 times
1 Answers
0
I might be responding a bit late. Even though I do not have a concrete answer to your question, I feel the direction in which I am heading might help you as well. env.CHANGE_TARGET is undocumented and not guaranteed to work always(If it ever worked). So, you need to use some scripting to get the target branch. I am using Windows batch files and node.js scripts to achieve the same. Below is the link to the question i posted recently.
Return a String from a Windows Batch file
As mentioned before, it is not working for me yet. I think I will need to install a plugin on my Jenkins to get it working as mentioned in their documentation below:
Hope my answer helps you

Anee
- 463
- 9
- 26