Home > database >  How to configure the application.properties externally in the Jenkins maven job?
How to configure the application.properties externally in the Jenkins maven job?

Time:05-11

I have a Springboot project and I'm trying to deploy it to the Azure web app via Jenkins job. Created maven project in Jenkins for compiling, testing, and deploying the projects are in the below name.

  1. CheckoutandBuild project - here I configured my bitbucket which has my source code. this job just fetches the source code and executes the maven command clean compile Note: due to security I don't commit my application.properties to the bitbucket branch.
  2. UnitTest project - based on the stable build of the CheckoutandBuild project, this job will execute the maven command test. I'm getting the below error while executing this project
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'azureADUtils': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'azure.openid.config.url' in value "${azure.openid.config.url}"
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'azure.config.url' in value "${azure.config.url}".

It is clearly saying it is expecting the value ${azure.config.url} which is available in my app.properties which I haven't committed in bitbucket.

Then how can I configure the properties file in Jenkins to make the build successful? I tried adding the app.properties in Manage Jenkins->Managed files of Jenkins, But it is not taking my properties file.

How to add and configure my app.properties in the Jenkins job? is there any other way to add my properties?

CodePudding user response:

You should be able to copy your managed files to your build in Jenkins like this plugin suggests.

By IMO you should reconsider your approach, the property file is an integrated part of the project. Does your entire property file is sensitive? Perhaps you could just leave the sensitive values with an environment variable placeholder, like this:

non-sensitive-property=value1234
sensitive-property=${MY_ENV_VAR}

See more details here

CodePudding user response:

You can pass your property while executing mvn command on Jenkins, considering you are using mvnw / mvn:

./mvnw  spring-boot:run \
 -Dspring-boot.run.arguments="--azure.config.url=https://url"

Or

./mvnw  spring-boot:run -Dspring-boot.run.jvmArguments="\
 -Dazure.config.url=https://url"

Hopefully this is what you are looking for.

  • Related