Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何从Spring启动代码中读取Gitlab(.Gitlab-ci.yml)环境变量?_Spring Boot_Kotlin_Gitlab_Environment Variables_Gitlab Ci - Fatal编程技术网

Spring boot 如何从Spring启动代码中读取Gitlab(.Gitlab-ci.yml)环境变量?

Spring boot 如何从Spring启动代码中读取Gitlab(.Gitlab-ci.yml)环境变量?,spring-boot,kotlin,gitlab,environment-variables,gitlab-ci,Spring Boot,Kotlin,Gitlab,Environment Variables,Gitlab Ci,在构建应用程序时,我试图读取从Gitlab配置中设置的环境变量,我这样做是为了达到这个目的: 我在spring boot应用程序的application.properties.yml中设置了一个变量: sf: apiKey: $SF_API_KEY 在.gitlab-ci.yml中,我定义了要设置的变量,如下所示: variables: SF_API_KEY: $SF_API_KEY 我只想能够从我的一个服务中读取该变量,如下代码所示: @Service class MyService

在构建应用程序时,我试图读取从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

 }
}
我做错什么了吗?如果有任何帮助,我将不胜感激。

请尝试(注意
SF\u API\u键周围的
{}
):

查看此占位符符号的详细位置。

尝试(注意
SF\u API\u键周围的
{}
):

看一看这个占位符符号的详细位置

sf:
 apiKey: ${SF_API_KEY}