Reputation: 10717
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?
Upvotes: 0
Views: 8083
Reputation: 89
In goals and options under build
clean package -Pdev
where dev is my profile name
Upvotes: -1
Reputation: 8011
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
Upvotes: 1
Reputation: 916
One way to do this is as below.
Step1: Setup profile in application.properties or application.yml
spring.profiles.active=${jenkins.profile}
Step2: Setup the environmentin jenkins folder.
Assuming you have folder structure like below.
XXXX_Pipelines --> Stage/MTF/PROD --> app1_pipleline/app2_piplelines
Setup Stage folder properties as jenkins.profile=stage
This will setup the environment variable at runtime.
Upvotes: 2