3

I have a Bamboo server that is currently setup to test my builds on my project. I want to start versioning my project using NPM version or grunt bump.

Here is the current Bamboo setup I have,

  1. Bamboo detects repo change
  2. Runs all the test
  3. If the branch is the 'master' branch, then do a post job of moving our production code into an artifactory (we just zip up the appropriate files and drop them into it).

I would like to be able to increment the version between step 2 and 3 if the branch is 'master'.

I'm trying to come up with a good solution for this.

I'm wondering if something like just doing npm version or npm bump is enough? It seems that I would want to them commit that back to the git repo?

Looking for some possible suggestions

Envin
  • 1,463
  • 8
  • 32
  • 69

1 Answers1

0

First detect that you're on the master branch. If so, do an npm version update. You also need to tell git to push to the remote repository rather than to the repo cached on the Bamboo server. For example, in a script task on your build plan:

npm install
npm run build

if [[ "${bamboo.planRepository.branchName}" == "master" ]]; then
    
    # configure git to use the remote repo
    git remote set-url origin ${bamboo.planRepository.1.repositoryUrl}
    rm .git/objects/info/alternates
    git fetch

    # update the local version
    # this will increment the last version number, commit and tag the commit
    npm version patch

    # create your artifact
    npm pack

    # push the version update
    git push
    git push --tags    
fi
Fergal
  • 5,213
  • 6
  • 35
  • 44
  • This will actually get you in an endless loop of Bamboo bumping a version on master, then detecting that remote has changes, pulling, bumping again, etc... It needs [skipci] too: https://community.atlassian.com/t5/Bamboo-questions/Skip-Bamboo-builds-using-commit-message/qaq-p/867248 – rantoniuk May 22 '21 at 15:27