1
votes

I have a Spring Boot application and I make use of Azure DevOps to automatically build/test the project and deploy the artifact.

My question is as follows: How can I build based on a specific application.profile? Right now it just builds but in my project I have the following 3 files:

  • application.properties
  • application-test.properties
  • application-acceptance.properties

How can I for example build based on "application-test.properties"?

Currently my code looks like this:

stages: 
 - stage: Build
displayName: Build stage
  jobs:
 - job: MavenPackageAndPublishArtifacts
displayName: Maven Package and Publish Artifacts
pool:vmImage: $(vmImageName)

steps:
- task: Maven@3
  displayName: 'Maven Package'
  inputs:
    mavenPomFile: 'pom.xml'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.11'
    jdkArchitectureOption: 'x64'

- task: CopyFiles@2
  displayName: 'Copy Files to artifact staging directory'
  inputs:
    SourceFolder: '$(System.DefaultWorkingDirectory)'
    Contents: '**/target/*.?(war|jar)'
    TargetFolder: $(Build.ArtifactStagingDirectory)

- upload: $(Build.ArtifactStagingDirectory)
  artifact: drop
1

1 Answers

1
votes

According to SpringBoot maven build war using specific application.properties

Setting the SPRING_PROFILES_ACTIVE environment variable will activate the intended profile. for example, in order to activate the qa profile, set the SPRING_PROFILES_ACTIVE environment variable to qa. Read more about profile specific properties here in Spring Boot Documentation.

About how to use environment, you could also take a look at this blog: Using Environment Variables in Azure DevOps Pipelines