英文:
How to (implicitly) pass environment variables to Maven build in gitlab-ci.yml for a Spring Boot application?
问题
在一个gitlab-ci.yml文件中,我正在使用Maven构建一个Spring Boot应用程序。要替换application.properties中的占位符@MY_PROP@(使用Maven资源插件),需要将MY_PROP作为-D参数传递给mvn命令。由于我的构建中有许多参数,是否有一种方法可以在不显式通过-D参数传递每个单独的环境参数的情况下将环境变量传递给Maven?
application.properties
my.prop=@MY_PROP@
gitlab环境变量
MY_PROP=4711
gitlab-ci.yml
Build:
image: maven:3-jdk-11
stage: build
script:
- mvn clean package deploy -s ci_settings.xml --batch-mode -DMY_PROP=$MY_PROP
英文:
In a gitlab-ci.yml I'm building a Spring Boot app using Maven. To replace placeholder @MY_PROP@ in application.properties (using the Maven resources plugin) MY_PROP is passed as -D parameter to the mvn command.
Since there are a lot of parameters in my build, is there a way to pass environment varaibles to Maven without explicitly passing each individual env parameter via -D?
application.properties
my.prop=@MY_PROP@
gitlab env variable
MY_PROP=4711
gitlab-ci.yml
Build:
image: maven:3-jdk-11
stage: build
script:
- mvn clean package deploy -s ci_settings.xml --batch-mode -DMY_PROP=$MY_PROP
答案1
得分: 1
From the Maven reference: https://books.sonatype.com/mvnref-book/reference/resource-filtering-sect-properties.html
You can do:
> env.*
>
> 环境变量,如 PATH
和 M2_HOME
,可以使用 env.*
前缀引用。
So in your pom.xml you can reference them as:
${env.MY_PROP}
In your case, to replace with resource plugin you can write:
my.prop=@env.MY_PROP@
英文:
From the Maven reference: https://books.sonatype.com/mvnref-book/reference/resource-filtering-sect-properties.html
You can do:
> env.*
>
> Environment variables like PATH
and M2_HOME
can be referenced using the env.*
prefix.
So in your pom.xml you can reference them as:
${env.MY_PROP}
In your case, to replace with resource plugin you can write:
my.prop=@env.MY_PROP@
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论