Issue
I need to run a Spring Boot app using different configuration files. In local I can do it with the following JVM Option:
-Dspring.profiles.active=e1
What's the way to do this when I run the app from a Jenkins job?
Solution
With the assumption that user knows .jenkins file, I provide below the code snippet.
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
If you do not want to write .jenkins file, you can follow the link and setup manually. 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.
mvnw spring-boot:run -Dspring.profiles.active=e1
Answered By - Sambit