0
votes

I have a multibranch pipeline job.

When the pipeline runs for the master branch I want to:

  1. Check if this scm push was a merge
  2. Get the name of the branch that was merged

This way when the master build runs I can see if and which branch branch was merged into it and then do stuff with that info.

It would be nice if this is a built in jenkins feature or if this info can just be read from the GitSCM class

1

1 Answers

1
votes

There is no straight way I guess. One workaround would be to use commands directly to fetch the details.

To find if the push is a merge commit, execute the following command:

git log --pretty=%P -n 1 "{commit id}"

It will give the parent commits for the given commit id. If there are two parents, then it is a merge commit.

To find the branch name of the merged commit:

git branch --contains "{commit id}"

This will return the branch names.