How can I find the base for a PR? (GitHub repo, Jenkins build)

The documentation for performing PR analysis does not help me, here, as it states I have to provide the PR’s key (I guess I can use the number after the “PR-” in the branch name), the PR’s branch (got that. It’s already in “sonar.branch.name”), and the base branch, but does not provide any indication how I can collect that information during my build.

I admit git is kind of a mess with branches, as any merge will show up in the graph as a potential base point, but apparently the Travis plugin is able to do this. Some help would be nice.

Cheers,
Bert Laverman

Hello @bert-laverman,

Most CI providers expose the PR key, base branch and target branch in the build as an environment variable. If a CI provider supports this, we will automatically read these environment variables and set-up the properties (this is the case for TravisCi).

For Jenkins this is not the case (although it seems that you can use env.CHANGE_ID when you are using multibranch pipelines).

If the PR key is configured we automatically resolve the base branch by using a GitHub API. If this is not the case you will have to configure this yourself.

When using Jenkins with a classical pipeline you might want to look at some plug-ins that expose this information in the build pipeline.

Hope that clears things up!