Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Adding release tags automatically based on semVer versioning whenever we merge a branch into master?

I want to add git tags to when I merge a PR into my master branch. Is there any better way to do this ? 
Currently I was looking in bitbucket pipeline but I don't know how to run the script when we have a merge commit and also to conditionally create the version name based on the branch name.

Let's say out version is like major.minor.patch then if the branch name is feature/ I will bump the minor version if it's fix/ I will bump the patch version.

 

currently I am trying to do this using this script below but I don't know how to get the branch name I am merging into master $BITBUCKET_BRANCH gives me master and not the feature/ branch

pipelines:

branches:

master:

- step:

name: Version and build

script:

- echo "Made a change in build ${BITBUCKET_BUILD_NUMBER}" >> changes.txt

- git add changes.txt

- git commit -m "Updating changes.txt with latest build number."

- BRANCH_NAME=$(echo ${BITBUCKET_PR_DESTINATION_BRANCH} | sed 's/\//./g')

- echo $BITBUCKET_PR_DESTINATION_BRANCH

- echo $BITBUCKET_BRANCH

- LAST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))

- echo $LAST_TAG

- MAJOR=$(echo $LAST_TAG | awk -F "." '{print $1}')

- MINOR=$(echo $LAST_TAG | awk -F "." '{print $2}')

- PATCH=$(echo $LAST_TAG | awk -F "." '{print $3}')

- echo $MAJOR

- echo $MINOR

- echo $PATCH

- if [ "$BRANCH_NAME" == "feature.*" ]; then NEW_TAG="$MAJOR.$(($MINOR + 1)).0"

- else NEW_TAG="$MAJOR.$MINOR.$(($PATCH + 1))"

- fi

- echo $NEW_TAG

- git tag -am "Tagging for release ${NEW_TAG}" ${NEW_TAG}

- git push origin ${NEW_TAG}



If there is any other better way to do this automated versioning it will be helpful too.

1 answer

0 votes
Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Feb 03, 2023

@Vishal Kashi hi. Try this:

git-release.sh file context

#!/usr/bin/env bash

# Release new git version

set -ex

##
# Step 1: Get version tag
##
tag=$(semversioner current-version)

##
# Step 2: Commit back to the repository
##
echo "Committing updated files to the repository..."
git add .
git commit -m "Update files for new version '${tag}' [skip ci]"
git push origin "${BITBUCKET_BRANCH}"

Add this to your yaml file:

script:
- pip install semversioner
- ./git-release.sh

Before run pipeline you should use semversioner for semantic versioning. Check this docs for more details.

Example with semversioner tool:

You should have `.semversioner` folder;

Then add the change:

semversioner add-change --type patch --description "Fix security vulnerability with authentication."

Then run your pipeline with script above.


Regards, Igor

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events