在Spring Boot应用程序的应用程序属性文件中使用Jenkins变量

Ano*_*ias 5 java groovy spring jenkins spring-boot

我有一个Spring Boot应用程序,可从Vault中提取秘密,我想在Spring Boot应用程序的应用程序属性文件中使用这些秘密。

def VAR = new groovy.json.JsonSlurper().parseText(secret)[0].VARKEY
if(VAR != ''){
    echo "Vault Secret pulled Successfully pass is "+VAR
}else{
    echo "Vault Secret Not Found"
}
Run Code Online (Sandbox Code Playgroud)

上面的代码成功设置了变量VAR,然后如何使用VAR在Spring Boot应用程序的应用程序属性文件中设置某些值?

谢谢

GAK*_*GAK 5

通过 application.properties 读取:

将VAR的值设置为java系统或环境并application.properties像这样读取它

my.app.prop=${ENV_VARIABLE}
Run Code Online (Sandbox Code Playgroud)

用于阅读 Jenkins 文件:

为了在 jenkins 文件中读取它,请编写一个 groovy 脚本并读取属性,例如System.properties[ENV_VARIABLE]

注意:我假设您的 Spring boot 应用程序和 Jenkins 在同一个 JVM 上运行。