Skip to content
Advertisement

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. 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?

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement