java - Sanitize version for docker image versioning. nebula.release

I have a pipeline to build a Docker image in every push to specific branches in my git repository. The problem is that semantic versioning is using '+' character to specifying the metadata section in the version name. I need to replace this char for another supported by Docker in the image name. There is any way to replace that character or use a custom version name?

I am using nebula.release to inferring the project version.

id 'nebula.release' version '10.1.1'

jib {
    to {
        image = "$version"
        auth {
            username = System.getenv('CI_REGISTRY_USER')
            password = System.getenv('CI_REGISTRY_PASSWORD')
        tags = ['latest']
    container {
        ports = ['8080']
        environment = [
        useCurrentTimestamp = true
    allowInsecureRegistries = true

jibDockerBuild.dependsOn bootJar

This is the error:

  • What went wrong: Execution failed for task ':jib'. Invalid image reference:

I created this task in my build.gradle file, Is there any way to reuse it?

task cleanVersion {

    ext.sanitizeVersion = { version ->
        return version.toString().replace('+', '_')
    doLast {
        println sanitizeVersion("$version")

I could use some help. Thanks in advance for your time.

1 Answer

  1. Denny- Reply


    Since build scripts are code and it looks like jib is an extension, project.version is a retrieval property (compared to a task output or something generated), you can use the same code you have in your current cleanVersion task to configure the extension.

    image = "${version.toString().replace('+', '_')}"

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>