Skip to content

Applying next tag for Maven SNAPSHOT builds #4399

@mcantrell

Description

@mcantrell

Environment:

  • Jib version: 3.4.4
  • Build tool: Maven
  • OS: MacOS

Description:
I'm attempting to define a phase tag that indicates the type of release for the image.

  • next for SNAPSHOT builds
  • latest for release builds

I haven't found any explicit configrations in the Jib documentation that allows for this, so I'm hoping to use a Maven profile or some other mechanism to set the jib.phase.tag property based on the project version.

All of my attempts to do this have failed. I'm wondering if this might be a feature request for Jib to support conditional tags based on the project version type.

Attempted Configrations:

Main plugin configuration in pom.xml:

<properties>
    <maven.build.timestamp.format>yyyyMMdd-HHmmss-SSS</maven.build.timestamp.format>
    <jib.phase.tag>latest</jib.phase.tag>
    <jib.image>**redacted**/${project.artifactId}:${jib.phase.tag}</jib.image>
</properties>
<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>3.4.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <from>
            <image>eclipse-temurin:21</image>
        </from>
        <to>
            <image>${jib.image}</image>
            <tags>
                <tag>${project.version}-${maven.build.timestamp}</tag>
                <tag>${project.version}</tag>
            </tags>
        </to>
        <container>
            <jvmFlags>
                <jvmFlag>-XX:MaxRAMPercentage=80.0</jvmFlag>
                <jvmFlag>-XX:MinRAMPercentage=80.0</jvmFlag>
            </jvmFlags>
        </container>
    </configuration>
</plugin>

I haven't found a way to do this with standard maven profiles because you can't use wildcard/regex patterns to detect -SNAPSHOT in the project.version:

<!-- this will not work -->
<profiles>
    <profile>
        <id>snapshot-build</id>
        <activation>
            <property>
                <name>project.version</name>
                <value>.*-SNAPSHOT</value>
            </property>
        </activation>
        <properties>
            <jib.phase.tag>next</jib.phase.tag>
        </properties>
    </profile>
</profiles>

I've also tried the build-helper-maven-plugin to set the property but the tag always ends up as latest:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>set-jib-phase-tag-for-snapshot</id>
            <goals>
                <goal>regex-property</goal>
            </goals>
            <configuration>
                <name>jib.phase.tag</name>
                <value>${project.version}</value>
                <regex>.*-SNAPSHOT</regex>
                <replacement>next</replacement>
                <failIfNoMatch>false</failIfNoMatch>
            </configuration>
        </execution>
    </executions>
</plugin>

Value

While the latest tag is usually used to indicate the latest stable release, next (npm naming convention) is used to indicate the latest development release.

It seems like maybe this would be a nice feature for Jib to support with a configuration option.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions