Skip to content

Instantly share code, notes, and snippets.

@GeorgeYan
Forked from RobertoGraham/post_push
Created September 9, 2019 06:45
Show Gist options
  • Save GeorgeYan/7034d0dce4b0aa28c4eebd7bb57366cc to your computer and use it in GitHub Desktop.
Save GeorgeYan/7034d0dce4b0aa28c4eebd7bb57366cc to your computer and use it in GitHub Desktop.
Docker Hub/Cloud Automated Build post_push hook to tag Maven project images with their version
#!/bin/sh
# Mounts PWD (pom.xml must be at root) on lightest Maven image and extracts the project version
VERSION=`docker run -v $(pwd):/usr/src/app \
-w /usr/src/app \
maven:3.6.0-jdk-8-alpine mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version \
-q \
-DforceStdout`
docker tag $IMAGE_NAME $DOCKER_REPO:$VERSION
docker push $DOCKER_REPO:$VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment