3

我有一个管道可以在每次推送到我的 git 存储库中的特定分支时构建一个 Docker 映像。问题是语义版本控制使用“+”字符来指定版本名称中的元数据部分。我需要将此字符替换为图像名称中 Docker 支持的另一个字符。有什么方法可以替换该字符或使用自定义版本名称?

我正在使用 nebula.release 来推断项目版本。

id 'nebula.release' version '10.1.1'

jib {
    to {
        image = "registry.gitlab.com.uy:5005/project/app:$version"
        auth {
            username = System.getenv('CI_REGISTRY_USER')
            password = System.getenv('CI_REGISTRY_PASSWORD')
        }
        tags = ['latest']
    }
    container {
        ports = ['8080']
        environment = [
                SPRING_OUTPUT_ANSI_ENABLED: 'ALWAYS',
        ]
        useCurrentTimestamp = true
    }
    allowInsecureRegistries = true
}

jibDockerBuild.dependsOn bootJar

这是错误:

  • 出了什么问题:任务“:jib”执行失败。

    com.google.cloud.tools.jib.image.InvalidImageReferenceException:无效的图像参考:registry.gitlab.com.uy:5005/project/app:1.0.0-rc.1.dev.0+108db18

我在 build.gradle 文件中创建了这个任务,有没有办法重用它?

task cleanVersion {

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

我可以使用一些帮助。在此先感谢您的时间。

4

1 回答 1

1

由于构建脚本是代码,它看起来像是jib一个扩展,project.version是一个检索属性(与任务输出或生成的东西相比),您可以使用当前cleanVersion任务中的相同代码来配置扩展。

image = "registry.gitlab.com.uy:5005/project/app:${version.toString().replace('+', '_')}"
于 2019-04-30T02:12:11.937 回答