How do I use the git commit id as a docker image tag in maven? -


i'm trying have docker images maven java project built , pushed in install , deploy phases respectively; , i'd images tagged current git commit id.

the problem facing maven-git-commit-plugin not seem export ${git.commit.id.abbrev} variable correctly consumption in docker-maven-plugin.

my parent pom.xml goes this:

<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">      <modelversion>4.0.0</modelversion>         <name>myproject</name>      <groupid>mygroup</groupid>     <artifactid>myartifact</artifactid>     <version>0.0.1-snapshot</version>     <packaging>pom</packaging>      <modules>         <module>mymodule</module>     </modules>      <properties>          <!-- dependency versions -->                <!-- stuff here...-->         <!-- plugin versions -->         <maven.enforcer.plugin.version>1.4.1</maven.enforcer.plugin.version>         <maven.shade.plugin.version>2.4.2</maven.shade.plugin.version>         <scala.maven.plugin.version>3.2.2</scala.maven.plugin.version>         <com.spotify.docker.plugin.version>0.3.8</com.spotify.docker.plugin.version>     </properties>      <dependencymanagement>         <dependencies>            <!-- stuff here...-->         </dependencies>     </dependencymanagement>      <build>          <pluginmanagement>             <plugins>                 <plugin>                     <groupid>com.spotify</groupid>                     <artifactid>docker-maven-plugin</artifactid>                     <version>${com.spotify.docker.plugin.version}</version>                     <executions>                         <execution>                             <id>docker-build</id>                             <goals>                                 <goal>build</goal>                             </goals>                             <phase>install</phase>                         </execution>                         <execution>                             <id>docker-push</id>                             <goals>                                 <goal>push</goal>                             </goals>                             <phase>deploy</phase>                         </execution>                     </executions>                     <configuration>                         <forcetags>true</forcetags>                         <baseimage>java</baseimage>                     </configuration>                 </plugin>                  <plugin>                     <groupid>pl.project13.maven</groupid>                     <artifactid>git-commit-id-plugin</artifactid>                     <version>2.2.0</version>                     <executions>                         <execution>                             <goals>                                 <goal>revision</goal>                             </goals>                         </execution>                     </executions>                      <configuration>                         <dateformattimezone>${user.timezone}</dateformattimezone>                         <verbose>true</verbose>                     </configuration>                 </plugin>              </plugins>         </pluginmanagement>          <plugins>         </plugins>      </build> </project> 

and plugins part of module pom.xml:

        <plugin>             <groupid>com.spotify</groupid>             <artifactid>docker-maven-plugin</artifactid>             <configuration>                 <imagename>docker-registry.nexus.bazaarvoice.com/${project.parent.artifactid}-${project.artifactid}:${git.commit.id.abbrev}</imagename>                 <entrypoint>["java", "-jar", "/${project.build.finalname}.jar"]</entrypoint>                 <!-- copy service's jar file target root directory of image -->                 <resources>                     <resource>                         <targetpath>/</targetpath>                         <directory>${project.build.directory}</directory>                         <include>${project.build.finalname}.jar</include>                     </resource>                     <resource>                         <targetpath>config</targetpath>                         <directory>${project.parent.basedir}/deploy/config/${project.artifactid}</directory>                         <include>*</include>                     </resource>                 </resources>             </configuration>         </plugin> 

i'm getting following error:

[error] failed execute goal com.spotify:docker-maven-plugin:0.3.8:build (docker-build) on project service: exception caught: template variable 'git.commit.id.abbrev' has no value -> [help 1] 

i've tried switching buildnumber-plugin same kind of error (using ${buildnumber} instead of ${git.commit.id.abbrev}).

what missing? docker plugin executing before git commit id plugin sets variables?

i had similar problem since invoking plugin directly (i have not bound plugin phases in pom, have invoke explicitly):

mvn -f mymodule/pom.xml docker:build -dforcetags -dpushimage 

with plugin conf:

  <plugin>     <groupid>com.spotify</groupid>     <artifactid>docker-maven-plugin</artifactid>     <configuration>         <imagename>registry/mymodule</imagename>         <imagetags>             <imagetag>${project.version}</imagetag>             <imagetag>latest</imagetag>             <imagetag>${git.commit.id.abbrev}</imagetag>         </imagetags>         <baseimage>java</baseimage>         <entrypoint>             ["java","-djava.security.egd=file:/dev/./urandom","-jar","/${project.build.finalname}.jar"]         </entrypoint>         <resources>             <resource>                 <targetpath>/</targetpath>                 <directory>${project.build.directory}</directory>                 <include>${project.build.finalname}.jar</include>             </resource>         </resources>     </configuration> </plugin> 

since maven-git-commit-plugin bound initialize phase, had invoke phase git plugin populated property

mvn initialize -f mymodule/pom.xml docker:build -dforcetags -dpushimage 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -