Jenkins automate the deployment javaweb project, to switch the database connection profile configuration file

First, the demand scenario

  In the verification process is automatic deployment by Jenkins, a met a problem: the development branch into the testing branch code from Git, database connection configuration or the development environment used by the database, but if by automating the deployment, automation directly from the testing branch when deploying a test environment, you need to switch the database connection configuration.

Second, the idea

  In "Jenkins + maven + Git achieving source deployment and release" , we have implemented a simple pull through code blocks of code, and then build, finally published to process Tomcat on the server, and here we do not discuss this process is not best practices, is simply trying to automate the process of deploying by Jenkins. In the actual verification process, there has been demand scenario mentioned above, is the need to modify the database connection profile. Jenkins has always been a the publishing process, related operations integrated with the platform, we can not consider after pulling code, build the project before, the database is configured to configure a test environment to replace it (this configuration is generally not based on changes)? Here we begin to verify the assumptions.

Third, the verification process
1, back up a test environment requires the database configuration file

  We in D: \ test directory, stores a application.yml configuration file, this file is a test environment requires a configuration file (in fact, you can consider it a single database configuration file jdbc configuration file).

2, in the construction of the project, increasing the replacement configuration file

  To achieve this, it is before building projects in progress, a step increase "Execute Windows batch command", then this step to increase the command to copy the file:

copy /Y d:\test\application.yml C:\Users\Administrator\.jenkins\workspace\test\src\main\resources

  The copy command is to copy the files to the specified directory, wherein / Y represents a direct coverage with the same name if the file exists, d: \ test \ application.yml need to copy files, C: \ Users \ Administrator.jenkins \ workspace \ test \ src \ main \ resources is the need to copy files to the directory. The command requires the directory based on the actual operating system, and backup configuration files were, because this verification is carried out in the windows environment, the use of a windows environment command.

Specific configuration as shown below:
Here Insert Picture Description

3, validation results

  After configuring the above command, you can re-click on the "build now" button, the redeployment of the project, this time to the project can be published to the server continues to verify that the configuration file has been modified. You can wait for the results of the deployment, if the original configuration can not connect to the database, this time, there will be prompted to log deploy deployment fails. It will appear the following error (the error may be other reasons also lead to system):

Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: FAIL - Deployed application at context path /jeesite-icity but context failed to start
Published 48 original articles · won praise 3 · Views 3113

Guess you like

Origin blog.csdn.net/hou_ge/article/details/103584488