简体   繁体   中英

How to update version automatically in pom.xml

I have pom.xml, which consist of docker image version, I am building my dockerfile from pom.xml, It consist of version, and the version for docker image keeps on changing, is there any automated way through which I can update the version so that every time the file takes the latest version, without manually editing the pom.xml file.

<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>
    <groupId>org.onboarding</groupId>
    <artifactId>onboarding-app</artifactId>
    <version>3.7.9-app</version>
    <name>Onboarding app for public use</name>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath />
    </parent>

Here the version 3.7.9-app, should automatically be updated, so that every time it takes the latest version.

My pom.xml file is placed on gitlab and I want to update it's version 3.7.9-app in my case automatically

If you wish to update your pom.xml version, you could run:

mvn versions:set -DnewVersion=$(version you need)

For instance, to get the curent git version and apply it to your pom.mxl:

 mvn versions:set -DnewVersion=$(git describe --tags --abbrev=0)

To get your docker image version, it depends how you build it. Is it with maven?

Most of the time, maven is in charge of the version and it will update git or docker tag version with the help of maven plugin (for instsance: https://maven.apache.org/maven-release/maven-release-plugin/ , https://maven.fabric8.io )

Otherwise, you might try to find a docker command that give you the version from your docker container local environnement. For instance, if the version is in the container environment variable and you know the container name, you could try to extract it with docker inspect --format="{{.Config.Env}}" and apply the version with the previous command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM