0

I'm pretty new to Bitbucket Pipelines and I encountered a problem. I'm creating a pipeline to deploy a new version of our Spring Boot application (which runs in a Kubernetes cluster) to our test environment. The problem I encountered is the versioning of our docker build. Our versioning is set up as the following:

alpha_0.1
alpha_0.2
beta_1.0
gamma_1.0
gamma_1.1

So every minor update/bugfix increases the build number by 0.1, and a major update increases the version by 1.0 + every major update gets a new version name.

Currently I have the next setup:

image: java:8

options:
  docker: true

branches:
  master:
    - step:
        caches:
          - gradle
        script:
          - ./gradlew test
          - ./gradlew build
          - docker build -t <application_name>/<version_name>_<version_number>

What is the best way to include the version_name and the version_number in the bitbucket pipeline? Until now we runned ruby script which allowed user input for version numbering, but bitbucket pipelines are not interactive.

Corne Elshof
  • 53
  • 1
  • 2
  • 5

2 Answers2

2

Assuming that alpha_0.1 etc. are tags and that the pipeline runs if a commit is tagged, you can get the tag for the current commit like this:

TAG=$(git tag --contains $BITBUCKET_COMMIT)

You can then use your favorite language or command-line tool to create the <version_name> and <version_number> from the tag you got. It may make sense to export the tag as a shell variable to be able to use it in a script.

BlueM
  • 3,658
  • 21
  • 34
0

This is one of the shippable.yml files I have, feel free to adapt it to Atlassian's pipelines.yml and Gradle:

language: java
jdk:
  - oraclejdk8
branches:
  only:
    - master
...
build:
  ci:
    # Generates build number
    - BUILD_NUMBER=`git log --oneline | wc -l`
    - echo "Build number':' ${BUILD_NUMBER}"
    # Sets version
    - mvn versions:set -DnewVersion=1.0.${BUILD_NUMBER}
    # Builds and pushes to Docker Hub
    - mvn package
    - docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_PASSWD} --email ${DOCKERHUB_EMAIL} https://index.docker.io/v1/
    - mvn -X docker:build -Dpush.image=true

My projects version (in pom.xml) are set to 0-SNAPSHOPT

This also uses Spotify's Maven plugin to build the Docker image instead of docker build -t ...

ootero
  • 3,235
  • 2
  • 16
  • 22
  • If you only need the build number, you should simply use the predefined `$BITBUCKET_BUILD_NUMBER`. (Unless you really want the *commit* number – which is what your script generates – instead of the *build* number.) – BlueM Feb 02 '18 at 11:57