Automatically update npm version number during bitbucket pull request
Asked Answered
F

0

7

I want to automatically increment a version number in my package.json as I merge in a pull request (to master). This will trigger a build and deploy using the correct version number.

Having to manually set the version number is irritating as multiple branches could expect to have the same version number, but only the first one merged in can use it, then the other pull request would need to be rejected due to the version number being incorrect.

My plan is to have a custom field on the jira issue associated with the pull request that specifies major/minor/patch, then use ApplicationLinkService in a bitbucket plugin (RepositoryMergeCheck seems the most appropriate) to grab that value.

I then want to modify the commit before it gets merged into master. It should grab the package.json from the head of master and use that and the jira field to determine the new value. Once it merges into master, bamboo automatically builds and attempts to publish so I need the version number to be correct before then.

I know of CommandBuilder to run git commands, but I can't see how it would help.

Is it possible to do this? The two issues I have with my current method are:

  • I couldn't find a way to modify the commit itself before it's merged in from the plugin.
  • I can't find a way to grab files from the branches (feature or master) from the plugin.
Frug answered 30/1, 2018 at 2:40 Comment(2)
Not sure if this will necessarily work for your setup, but have you considered using tags? Bitbucket has pretty good support for this and your CI pipeline could grab this tag value. Maybe tags are only created for your main/release branch so merging in multiple branches are not an issue since they will be sequential.Giordano
What about using the Bamboo build number environment variable (${bamboo.buildNumber})? This is a global bamboo variable that auto increments with each build. You could inject it into your package.json at the start of a build triggered by a pull request.Mennonite

© 2022 - 2024 — McMap. All rights reserved.