简体   繁体   English

如何在 Jenkins maven 作业中从外部配置 application.properties?

[英]How to configure the application.properties externally in the Jenkins maven job?

I have a Springboot project and I'm trying to deploy it to the Azure web app via Jenkins job.我有一个 Springboot 项目,我正在尝试通过 Jenkins 作业将其部署到 Azure Web 应用程序。 Created maven project in Jenkins for compiling, testing, and deploying the projects are in the below name.在 Jenkins 中创建的用于编译、测试和部署项目的 maven 项目名称如下。

  1. CheckoutandBuild project - here I configured my bitbucket which has my source code. CheckoutandBuild项目 - 在这里我配置了包含我的源代码的 bitbucket。 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.这项工作只是获取源代码并执行 maven 命令clean compile注意:由于安全性,我不会将application.properties提交到 bitbucket 分支。
  2. UnitTest project - based on the stable build of the CheckoutandBuild project, this job will execute the maven command test . UnitTest项目 - 基于 CheckoutandBuild 项目的稳定构建,此作业将执行 maven 命令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.很明显,它期望值${azure.config.url}在我的app.properties中可用,而我没有在 bitbucket 中提交。

Then how can I configure the properties file in Jenkins to make the build successful?那么如何在 Jenkins 中配置属性文件以使构建成功呢? I tried adding the app.properties in Manage Jenkins->Managed files of Jenkins, But it is not taking my properties file.我尝试在Manage Jenkins->Managed files of Jenkins 中添加app.properties ,但它没有占用我的属性文件。

How to add and configure my app.properties in the Jenkins job?如何在 Jenkins 作业中添加和配置我的app.properties is there any other way to add my properties?还有其他方法可以添加我的属性吗?

You should be able to copy your managed files to your build in Jenkins like this plugin suggests.您应该能够像这个插件建议的那样将您的托管文件复制到您在 Jenkins 中的构建。

By IMO you should reconsider your approach, the property file is an integrated part of the project.通过 IMO,您应该重新考虑您的方法,属性文件是项目的一个组成部分。 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 在此处查看更多详细信息

You can pass your property while executing mvn command on Jenkins, considering you are using mvnw / mvn:考虑到您使用的是 mvnw / mvn,您可以在 Jenkins 上执行 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.希望这是您正在寻找的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在骆驼测试中配置 application.properties? - How to configure application.properties in camel tests? 如何使用 Maven Archetype 在 application.properties 中编写属性 - How to write properties in application.properties using Maven Archetype 如何配置Spring以从jar外部加载application.properties? - How to configure Spring to load application.properties from outside of jar? Spring Boot 2:如何使用application.properties文件配置HikariCP - Spring Boot 2: How to configure HikariCP using application.properties file 如何在 Maven pom.xml 中重用 application.properties (Spring Boot) 中的属性? - How to reuse properties from application.properties (Spring Boot) in Maven pom.xml? 如何在 Spring 启动 Maven 项目中移动 application.properties 或执行外部属性 - How to Move application.properties or Do External Properties in Spring Boot Maven Project 如何使用Spring Boot在application.properties中注入Maven配置文件的属性 - how to inject maven profile's properties in application.properties with spring boot 如何排除默认的application.properties在Spring启动项目的Maven中使用配置文件添加自定义属性文件? - How to exclude default application.properties add custom properties file using profiles in maven for spring boot project? 如何将 Spring Data JPA 正确配置到 Spring Boot 2.X 应用程序的 application.properties 配置文件中? - How to correctly configure Spring Data JPA into the application.properties configuration file of a Spring Boot 2.X application? 使用properties-maven-plugin选择application.properties - Choosing application.properties using properties-maven-plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM