【发布时间】:2021-01-28 11:48:36
【问题描述】:
我正在尝试在构建应用程序时从 Gitlab 配置中读取正在设置的环境变量,我这样做是为了实现该目的:
我在我的 spring boot 应用的 application.properties.yml 中设置了一个变量:
sf:
apiKey: $SF_API_KEY
在.gitlab-ci.yml中,我定义了要设置的变量,如下:
variables:
SF_API_KEY: $SF_API_KEY
我想要的只是能够从我的一项服务中读取该变量,如下面的代码所示:
@Service
class MyService(@Value("\${sf.apiKey}") val apiKey: String)
{
fun doSomething(){
//i am seeing the variable is being set by gitlab in the build logs but
// it is not being read here properly
var result = apiKey;
logger.info { "***check apiKey: $apiKey" }
//This line lgs $SF_API_KEY as a value of my variable, but not the
// real value
}
}
我做错了吗?我将不胜感激。
【问题讨论】:
标签: spring-boot kotlin gitlab environment-variables gitlab-ci