Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tag a git repo in a bamboo build

Tags:

I'm trying to tag the git repo of a ruby gem in a Bamboo build. I thought doing something like this in ruby would do the job

`git tag v#{current_version}` `git push --tags` 

But the problem is that the repo does not have the origin. somehow Bamboo is getting rid of the origin Any clue?

like image 861
Allen Bargi Avatar asked Dec 09 '14 04:12

Allen Bargi


People also ask

Can you tag a GitHub repo?

Yes, we can add tags directly to GitHub. To sync the same with your local repository, you need to pull the changes using Git.

How do I add a tag to a repository?

In order to create a new tag, you have to use the “git tag” command and specify the tag name that you want to create. As an example, let's say that you want to create a new tag on the latest commit of your master branch. To achieve that, execute the “git tag” command and specify the tagname.


1 Answers

Yes, if you navigate to the job workspace, you will find that Bamboo does not do a straightforward git clone "under the hood", and the the remote is set to an internal file path.

Fortunately, Bamboo does store the original repository URL as ${bamboo.repository.git.repositoryUrl}, so all you need to do is set a remote pointing back at the original and push to there. This is what I've been using with both basic Git repositories and Stash, creating a tag based on the build number.

git tag -f -a ${bamboo.buildNumber} -m "${bamboo.planName} build number ${bamboo.buildNumber} passed automated acceptance testing." ${bamboo.planRepository.revision} git remote add central ${bamboo.planRepository.repositoryUrl} git push central ${bamboo.buildNumber} git ls-remote --exit-code --tags central ${bamboo.buildNumber}  

The final line is simply to cause the task to fail if the newly created tag cannot be read back.

EDIT: Do not be tempted to use the variable ${bamboo.repository.git.repositoryUrl}, as this will not necessarily point to the repo checked out in your job.

Also bear in mind that if you're checking out from multiple sources, ${bamboo.planRepository.repositoryUrl} points to the first repo in your "Source Code Checkout" task. The more specific URLs are referenced via:

${bamboo.planRepository.1.repositoryUrl} ${bamboo.planRepository.2.repositoryUrl} ... 

and so on.

like image 170
RCross Avatar answered Sep 18 '22 12:09

RCross