问题描述
我有一个应用程序,该应用程序要根据运行的配置文件推送到存储库A
或B
。
例如:
如果我在Jenkins sh "./mvnw package -Pint verify -DskipTests jib:dockerBuild"
中运行它,它应该推送到我们的集成注册表。
如果我在Jenkins sh "./mvnw package -Pprod verify -DskipTests jib:dockerBuild"
中运行它,它应该推送到我们的生产存储库中。
我已经这样设置了pom:
<from>
<image>adoptopenjdk:11-jre-hotspot</image>
</from>
<to>
<image>${docker.repository.url}/${docker.image.prefix}/${project.artifactId}</image>
<tags>
<tag>${project.version}-${spring.profiles.active}-${git.commit.id.abbrev}</tag>
</tags>
</to>
如何使其以这种特定方式表现?
解决方法
那很容易:D。您只需要在<properties>
部分中定义一个<profile>
部分。这些属性将在您运行指定的配置文件时添加(我强烈感觉它确实会覆盖全局<properties>
部分中设置的所有属性)。
例如:
<profiles>
<profile>
<id>int</id>
<properties>
<docker.repository.url>https://your.docker.registry</docker.repository.url>
</properties>
</profile>
</profiles>
关于profiles documentation page的更多信息,特别是可以在配置文件中使用哪些元素。