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

Use project version as docker image tag

Alexander Hofmeister June 4, 2019

Hi everyone! 

I have following configuration which builds and pushes my project as image into dockerhub

pipelines:
branches:
master:
- step:
services:
- docker
script:
- mvn clean install
- export IMAGE_NAME=org/project:$BITBUCKET_COMMIT
- docker build -t $IMAGE_NAME .
- docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
- docker push $IMAGE_NAME

 

This works fine and was easy to setup. Now, I want to tag my images with the current version of my project, which is specified in the *pom.xml* which lies in the root directory. 

How can I read/extract/store the version of my project and use it as tag for a docker image?

 

Cheers,


Alexander

 

1 answer

0 votes
Vishal Vyas June 4, 2019

Please have a look at below if it could help you.

```

export VERSION=$(awk 'FNR==5' pom.xml)

```

it will export 5th line of the file.

 

```

docker build -t $IMAGE_NAME:VERSION .

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events