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

Pipelines include tag when pushing to master?

aberkow
Contributor
March 27, 2017

Is it possible to build a `bitbucket-pipelines.yml` script that appends a tag when pushing to the master branch? I know I can do this when specifically pushing to a tag via the BITBUCKET_TAG environment variable. My current script has this...

master:
      - step:
          script:
            - composer install
            - composer run-script build
            - zip -FSr uc-foi-database-${BITBUCKET_TAG}.zip ./ -x@exclude.lst #${BITBUCKET_TAG} is a default BB variable.
            - curl -u ${BB_AUTH_STRING} -X POST "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"uc-foi-database-${BITBUCKET_TAG}.zip"

However, this results in `uc-foi-database-.zip` and I'd like `uc-foi-database-1.0.0.zip`

Thanks!

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Matt Ryall
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2017

If your commits are already tagged through some other process, you can use git describe to find the most recent tag on the current branch and use that in your script. You can grab it into an environment variable like this:

pipelines:
  branches:
    master:
      - step:
          script:
            - ...
            - export GIT_TAG=`git describe`
            - zip -FSr uc-foi-database-${GIT_TAG}.zip ./ -x@exclude.lst
            - ...

If you want to be sure that the tag is on the exact commit running in your pipeline, you could use git describe --exact-match.

aberkow
Contributor
March 28, 2017

@Matt Ryall This is exactly what I needed. Thanks very much!

For anyone who comes later I ended up using `git describe --tags --abbrev=0` and then changing the file name to ${BITBUCKET_REPO_SLUG} to make the whole thing more generic/portable.

0 votes
Steven Vaccarella
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2017

I'm not sure I understand exactly what you're trying to achieve. Do you want to create a new tag every time you push to master? How do you want the name of the tag to be generated?

TAGS
AUG Leaders

Atlassian Community Events