coya
coya

Reputation: 264

maven-release-plugin release:branch - Avoid commit to original branch

I have just hit a roadblock and would really need some insight from someone who knows the maven-release-plugin. I am trying to use the plugin for operating with my pom file, but without having it touching/committing to the main branch, but to a separate branch so that I can later on PR from there and get the review+approval required by the branch protection policy in my repos.

Context

  1. We use github, and the company is enforcing a new branch protection policy in our main branches for security reasons mainly.
  2. I have been using a jenkins pipeline for releasing and delivering my code which in turn, uses the maven-release-plugin for tagging the repo, and switching the version in the pom.xml, etc.
  3. When using github's branch protection, the release plugin cannot do the usual operations, because it cannot push straight to the main branch.

My research

I found out that the plugin supports creating a branch in the process of releasing, that would be exactly what I am looking for. So, I built the environment for trying this out:

and started running some tests. The closest to being successful, was this line (version number is not important):

mvn --batch-mode release:branch '-DbranchName=release-v1.2.1' -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false

I started with the version in the pom set to the value of the version I am releasing (it is not great, but I am willing to make that commit myself). I have checked the release:prepare docs but found nothing that would help me achieving my goal.

My question

Is there any way of telling the plugin, not to make any commits to the original branch, so that it does not get rejected by the branch protection? I always get at least a commit to the main branch like this one:

* 934af86 2020-04-27 | [maven-release-plugin] prepare branch release-v1.2.1 (HEAD -> master) [Commiter Name]

Upvotes: 3

Views: 2292

Answers (1)

Matjaz
Matjaz

Reputation: 484

I know it's late to answer this but I just had the same issue and maybe someone else will search for this as well.

My configuration:

  • Jenkins
  • SCM Manager (Sonia)
  • Git master repo restricted for PRs only

What I end up doing was checking out to new branch and do the release from there. In my SCM-Manager I removed all priviledges for this branch from other users except for jenkis to protect it from being written directly.

So in jenkins project configuration I have set "Branches to build" to "*/Master". Then I added "Check out to specific local branch" in "Additional Behaviours". In branch name I have put "master_release". Your branch should be shown when you do release for the first time.

Since this was first release I will update this answer if I encounter any issues on next iteration but from my perspective it should work.

Upvotes: 1

Related Questions