我正在尝试读取正在构建应用程序时从 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 - 如何从 Spring Boot 代码中读取 Gitlab (.gitlab-ci.yml) 环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64347080/