[英]How to pass Spring profile to Spring Boot application run by Jenkins Job?
I need to run a Spring Boot app using different configuration files.我需要使用不同的配置文件运行 Spring Boot 应用程序。 In local I can do it with the following JVM Option:
在本地,我可以使用以下 JVM 选项来完成:
-Dspring.profiles.active=e1
What's the way to do this when I run the app from a Jenkins job?当我从 Jenkins 作业运行应用程序时,有什么方法可以做到这一点?
One way to do this is as below.一种方法如下。
Step1: Setup profile in application.properties or application.yml步骤 1:在 application.properties 或 application.yml 中设置配置文件
spring.profiles.active=${jenkins.profile}
Step2: Setup the environmentin jenkins folder.第二步:在 jenkins 文件夹中设置环境。
Assuming you have folder structure like below.假设您具有如下所示的文件夹结构。
XXXX_Pipelines --> Stage/MTF/PROD --> app1_pipleline/app2_piplelines XXXX_Pipelines --> Stage/MTF/PROD --> app1_pipleline/app2_piplelines
Setup Stage folder properties as jenkins.profile=stage将 Stage 文件夹属性设置为 jenkins.profile=stage
This will setup the environment variable at runtime.这将在运行时设置环境变量。
With the assumption that user knows .jenkins file, I provide below the code snippet.假设用户知道 .jenkins 文件,我在代码片段下方提供。
node {
.... Other code
stage("development") {
withEnv(['JENKINS_NODE_COOKIE=someName']) {
sh 'nohup ./mvnw spring-boot:run -Dspring.profiles.active=e1 &'
}
}
}
For more details and reference, check below the link.有关更多详细信息和参考,请查看以下链接。 https://www.baeldung.com/jenkins-pipelines
https://www.baeldung.com/jenkins-pipelines
If you do not want to write .jenkins file, you can follow the link and setup manually.如果你不想写 .jenkins 文件,你可以按照链接手动设置。 https://medium.com/finoit/continues-integration-using-jenkins-for-java-spring-4439ecd23bec
https://medium.com/finoit/continues-integration-using-jenkins-for-java-spring-4439ecd23bec
In case of gradlew clean build, you can provide the the following command.在 gradlew clean build 的情况下,您可以提供以下命令。
mvnw spring-boot:run -Dspring.profiles.active=e1
In goals and options under build在构建的目标和选项中
clean package -Pdev
where dev is my profile name其中 dev 是我的个人资料名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.