Application program automatic construction and deployment method based on script and Jenkins

By writing automation scripts in the CentOS system and combining them with Jenkins, the automated building and deployment of applications was achieved, solving the problems of low efficiency, error susceptibility and poor consistency in existing technologies. This supports rapid iterative development and improves the efficiency and accuracy of building and deployment.

CN121560341APending Publication Date: 2026-02-24GUANGDONG CHENGZHI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511646676.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-11
Publication Date
2026-02-24

AI Technical Summary

Technical Problem

Existing technologies suffer from inefficiency, error-proneness, difficulty in ensuring consistency, and inability to meet the needs of rapid iterative development in application building and deployment processes.

Method used

By writing automation scripts in the CentOS system and combining them with Jenkins, the application can be built and deployed automatically. This includes automated operations such as building, packaging, stopping, copying, and starting the service. Maven commands are used for building, scp commands are used for copying files, and automated tasks are triggered through the automated integration of Jenkins with GitLab repositories.

Benefits of technology

It automates the entire application building and deployment process, improving efficiency, accuracy, and consistency, supporting rapid iterative development, and reducing manual intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121560341A_ABST
    Figure CN121560341A_ABST
Patent Text Reader

Abstract

The invention discloses an application program automatic construction and deployment method based on scripts and Jenkins, which is characterized by comprising the following steps: step 1, compiling automatic scripts in a CentOS system, the scripts including a construction script, a packaging script, a service stopping script, a copying script and an application service starting script; 2, configuring a task in the Jenkins, associating the automatic script with the Jenkins, and setting a code to automatically trigger the Jenkins task when the code is submitted to a GitLab warehouse; 3, when codes are submitted to a GitLab warehouse, Jenkins automatically detects code updating and triggers a task, the automatic script is called to sequentially execute construction, packaging, service stopping, application service copying and application service starting operation, automatic construction and deployment of the application program are completed, compared with the prior art, full-process automation of application program construction and deployment is achieved, and the application program construction and deployment efficiency is improved. Efficiency, accuracy and consistency are improved, rapid iterative development is supported, and dependence on operation and maintenance manpower is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer software operation and maintenance technology, and in particular to a method for automated application building and deployment based on scripts and Jenkins. Background Technology

[0002] First, manual operation is inefficient. After completing the code, developers need to manually execute a series of complex commands to perform build and packaging operations. For example, when building a Java application, build tools such as Maven or Gradle are used, requiring manual input of build commands and waiting for compilation and dependency downloads to complete. This process is not only time-consuming, but developers also need to constantly monitor the build process to prevent errors. Similarly, the packaging stage requires manually executing packaging commands to package the built program into a deployable format, such as a JAR or WAR file. For large projects, these operations can consume a significant amount of time due to complex dependencies and cumbersome configurations.

[0003] Secondly, manual operation is prone to errors. Due to the numerous steps involved in the build and deployment process, including many parameter configurations and command executions, errors are inevitable with manual operation. For example, when configuring build tool parameters, an incorrect version number might be entered carelessly, leading to dependency download errors and causing the build to fail. Similarly, when stopping and starting application services, incorrect operation sequences could prevent the service from starting properly, affecting the normal use of the software.

[0004] Furthermore, manual operations are difficult to guarantee consistency. Different operations personnel may use different methods when performing build and deployment operations due to differences in personal habits or understanding of the process. This can lead to variations in the application build and deployment process across different environments, making software maintenance and troubleshooting more difficult. For example, subtle differences in deployment methods between development and testing environments may cause some functions that work correctly in the development environment to malfunction in the testing environment, increasing the difficulty and cost of troubleshooting.

[0005] Furthermore, manual operations cannot meet the demands of rapid iterative development. With the rise of agile development and DevOps, software development is accelerating, and the timeliness requirements for application building and deployment are increasing. Traditional manual methods cannot complete frequent build and deployment tasks in a short period, severely impacting software delivery cycles and reducing a company's market competitiveness.

[0006] In conclusion, the existing methods of manually building and deploying applications have significant shortcomings in terms of efficiency, accuracy, consistency, and support for rapid iterative development. There is an urgent need for an automated solution to improve operational efficiency and quality. Summary of the Invention

[0007] The purpose of this invention is to propose an automated application building and deployment method based on scripts and Jenkins, which can solve at least one of the above-mentioned technical problems. The technical solution of this invention is as follows: A method for automated application building and deployment based on scripts and Jenkins, characterized by the following steps: Step 1: Write automation scripts in the CentOS system. The scripts include build scripts, packaging scripts, service stop scripts, copy scripts, and application service start scripts. Step 2: Configure the task in Jenkins, associate the automation script with Jenkins, and set it to automatically trigger the Jenkins task when code is committed to the GitLab repository; Step 3: When the code is committed to the GitLab repository, Jenkins automatically detects code updates and triggers a task, which calls the automated script to sequentially execute the build, package, stop service, copy, and start application service operations to complete the automated build and deployment of the application.

[0008] Furthermore, the build script is used to perform the following operations: Define project path variables; Use Maven commands to perform build operations, including clearing historical build files, downloading dependencies, and compiling and packaging. Monitor network status and automatically attempt to reconnect and continue downloading dependencies when the network is interrupted.

[0009] Furthermore, the packaging script is used to package the generated files and related configuration files into a compressed package.

[0010] Furthermore, the stop service script is used to detect and terminate running application service processes.

[0011] Furthermore, the copy script is used to remotely copy the packaged files to a specified directory on the target server using the scp command, and automatically handles permission issues.

[0012] Furthermore, the application service startup script is used to start the application service on the target server and output logs to a specified file.

[0013] Furthermore, the configuration of the Jenkins task includes: Set source code management to Git and associate it with the GitLab repository address; Configure the cleanup workspace in the build environment; The automation scripts are called sequentially during the build process; Configure post-build actions, including email notifications of build status.

[0014] Furthermore, before executing the build script, the Jenkins task determines whether to perform the build operation by checking if the code has been updated.

[0015] In summary, the advantages of this invention over the prior art are: This invention automates the entire process of application building and deployment, improving efficiency, accuracy, and consistency, while supporting rapid iterative development and reducing reliance on manpower for operations and maintenance. Attached Figure Description

[0016] Figure 1 This is a schematic diagram of the overall process of the present invention.

[0017] Figure 2 This is a schematic diagram of the Jenkins task configuration of the present invention. Detailed Implementation

[0018] The present invention will be further described below with reference to the accompanying drawings and specific embodiments: like Figures 1 to 2 The following describes a script-based automated application build and deployment method using Jenkins: (1) The build script first defines the project path variable `project_path=" / home / user / projects / my_project"`. A while loop continuously checks network connectivity, using the ping command to test the connection to 8.8.8.8. If the network is unreachable, it waits 5 seconds and then retryes. After the network is connected, the `mvn clean install` command is executed, building the project based on the `pom.xml` file in the project, including clearing historical build files, downloading dependencies, and compiling and packaging.

[0019] (2) Packaging script: Use the tar command to package the generated JAR file (located in the target directory) and the project configuration file (located in the src / main / resources directory) into a compressed file named my_project.tar.gz. The specific command is: `tar -czvf my_project.tar.gz $project_path / target / my_project.jar $project_path / src / main / resources / config.properties`.

[0020] (3) Stop service script: Use the `ps` command in conjunction with `grep` to find the currently running `my_project.jar` service process, and then use `awk` to extract the process ID. If a running process is found, use the `kill -9` command to forcibly terminate the process, ensuring the service is completely stopped.

[0021] (4) Copy script: Use the `scp` command to transfer the packaged compressed file `my_project.tar.gz` to the specified directory ` / var / www / my_project / ` on the target server (user@target_server). Then, remotely execute the `chmod` command via SSH to set the permissions of the target directory to 755, ensuring the file is accessible.

[0022] (5) Start the application service script: Connect to the target server via SSH, navigate to the application deployment directory / var / www / my_project / , and use the command nohup java -jar to start the application service in the background and output the runtime log to the nohup.out file.

[0023] 2. Jenkins Configuration Phase (1) Installation and basic configuration: After installing the Jenkins service on the server and completing the basic configuration, set the installation paths for tools such as Maven and Git in the global tool configuration page of system management to ensure that Jenkins can call these tools normally.

[0024] (2) Create and configure a Jenkins task: Create a new freestyle project named "my_project_build_and_deploy". In the source code management section, select Git, and fill in the GitLab repository address and authentication information to enable Jenkins to obtain the source code. In the build environment, check the "Delete workspace before build starts" option to ensure that the workspace is cleaned up before each build. Add an "Execute shell" step in the build section, and enter the execution commands for the five scripts mentioned above in sequence. Configure email notifications in the post-build actions to set up email alerts for successful or failed builds.

[0025] 3. Automated process execution When developers commit code to a GitLab repository, Jenkins automatically detects the code changes and triggers a build task. Once the task starts, Jenkins will perform the following operations in sequence: Pull the latest code from the GitLab repository; Execute the build script to complete the project compilation and packaging; Execute the packaging script to generate the deployment package; Execute a service stop script on the target server to terminate the old version of the service; The copy script will transfer the new deployment package to the target server. Run the startup script on the target server to run the new version of the application.

[0026] The entire process requires no manual intervention and is completed automatically by Jenkins. Once the build is complete, the system automatically sends email notifications to relevant personnel based on the configuration. In this way, the entire application process, from code submission to deployment, is fully automated.

[0027] The foregoing has shown and described the basic principles and main features of the present invention, as well as its advantages. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to the present invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for automated application building and deployment based on scripts and Jenkins, characterized in that, Includes the following steps: Step 1: Write automation scripts in the CentOS system. The scripts include build scripts, packaging scripts, service stop scripts, copy scripts, and application service start scripts. Step 2: Configure the task in Jenkins, associate the automation script with Jenkins, and set it to automatically trigger the Jenkins task when code is committed to the GitLab repository; Step 3: When the code is committed to the GitLab repository, Jenkins automatically detects code updates and triggers a task, which calls the automated script to sequentially execute the operations of building, packaging, stopping the service, copying, and starting the application service, thus completing the automated building and deployment of the application.

2. The method for automated application building and deployment based on scripts and Jenkins according to claim 1, characterized in that... The build script is used to perform the following operations: Define project path variables; Use Maven commands to perform build operations, including clearing historical build files, downloading dependencies, and compiling and packaging. Monitor network status and automatically attempt to reconnect and continue downloading dependencies when the network is interrupted.

3. The method for automated application building and deployment based on scripts and Jenkins according to claim 1, characterized in that... The packaging script is used to package the generated files and related configuration files into a compressed package.

4. The method for automated application building and deployment based on scripts and Jenkins according to claim 1, characterized in that... The stop service script is used to detect and terminate running application service processes.

5. The method for automated application building and deployment based on scripts and Jenkins according to claim 1, characterized in that... The copy script is used to remotely copy the packaged files to a specified directory on the target server using the scp command, and automatically handles permission issues.

6. The method for automated application building and deployment based on scripts and Jenkins according to claim 1, characterized in that... The application service startup script is used to start the application service on the target server and output logs to a specified file.

7. The method for automated application building and deployment based on scripts and Jenkins according to claim 1, characterized in that... The configuration of the Jenkins task includes: Set source code management to Git and associate it with the GitLab repository address; Configure cleanup of the workspace in the build environment; The automation scripts are called sequentially during the build process; Configure post-build actions, including email notifications of build status.

8. The method for automated application building and deployment based on scripts and Jenkins according to claim 7, characterized in that... Before executing the build script, the Jenkins task determines whether to perform the build operation by checking if the code has been updated.