CN116400934A - Project automatic deployment method based on jenkins - Google Patents

Project automatic deployment method based on jenkins Download PDF

Info

Publication number
CN116400934A
CN116400934A CN202310671357.1A CN202310671357A CN116400934A CN 116400934 A CN116400934 A CN 116400934A CN 202310671357 A CN202310671357 A CN 202310671357A CN 116400934 A CN116400934 A CN 116400934A
Authority
CN
China
Prior art keywords
deployed
file
server
deployment
backup
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202310671357.1A
Other languages
Chinese (zh)
Other versions
CN116400934B (en
Inventor
刘东明
刘少轻
付伟
于洪雷
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Suixin Cloud Chain Technology Co ltd
Original Assignee
Beijing Suixin Cloud Chain Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Suixin Cloud Chain Technology Co ltd filed Critical Beijing Suixin Cloud Chain Technology Co ltd
Priority to CN202310671357.1A priority Critical patent/CN116400934B/en
Publication of CN116400934A publication Critical patent/CN116400934A/en
Application granted granted Critical
Publication of CN116400934B publication Critical patent/CN116400934B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1433Saving, restoring, recovering or retrying at system level during software upgrading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • G06F11/1469Backup restoration techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • G06F8/62Uninstallation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/06Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/51Discovery or management thereof, e.g. service location protocol [SLP] or web services
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to the technical field of service deployment, in particular to a jenkins-based project automatic deployment method, which aims at solving the problem of how to efficiently and accurately realize project automatic deployment. To this end, the method of the invention comprises: acquiring a file to be deployed related to project parameters constructed by jenkins service in a first server, wherein the file to be deployed is a newly built file to be deployed or a backup file to be deployed, and the backup file to be deployed is obtained by backup before the newly built file to be deployed is newly built; establishing an automatic interaction channel between the first server and the second server; sending the file to be deployed to a second server through the automatic interaction channel; and responding to the task restarting of the second server, and starting the file to be deployed to run. And realizing project deployment and operation of projects to be deployed in the second server by establishing an automatic interaction channel. The automatic deployment can improve the deployment efficiency; the risk of human errors is reduced, and the accuracy and stability of deployment are ensured.

Description

Project automatic deployment method based on jenkins
Technical Field
The invention relates to the technical field of service deployment, and particularly provides a jenkins-based project automatic deployment method.
Background
In the process of operation and maintenance, project deployment is one of the works of operation and maintenance. The current project deployment method is to realize automatic deployment and test through a jenkins tool platform. The general flow of project development and deployment based on jenkins is as follows: firstly, submitting project changes to be deployed to a gitlab version code warehouse; monitoring the change of branches in a gitlab version code warehouse through jenkins, and triggering pipeline construction when the change meets preset conditions, namely triggering project deployment flow; judging the item type according to the variable name extracted from the gitlab version code warehouse by jenkins, and compiling codes; and (5) performing manual deployment after compiling. While monitoring branch changes in the code warehouse triggers automated compilation flows, deployment requires manual deployment implementation, making project deployment inefficient, error prone, and time and effort consuming.
Accordingly, there is a need in the art for a new project auto-deployment solution to the above-described problems.
Disclosure of Invention
In order to overcome the above-mentioned drawbacks, the present invention is directed to providing an automatic project deployment method based on jenkins, which solves or at least partially solves the technical problem of how to efficiently and accurately implement automatic project deployment.
In a first aspect, the present invention provides a jenkins-based project automatic deployment method, executed by a shell script, including:
acquiring a file to be deployed related to project parameters constructed by jenkins service in a first server, wherein the file to be deployed is a newly built file to be deployed or a backup file to be deployed, and the backup file to be deployed is obtained by backup before the newly built file to be deployed is newly built;
establishing an automatic interaction channel between the first server and the second server;
sending the file to be deployed to a second server through the automatic interaction channel;
and responding to the task restarting of the second server, and starting the file to be deployed to run.
In one embodiment, the obtaining the file to be deployed related to the project parameters constructed by the jenkins service in the first server includes:
and executing corresponding operation according to the preset item type to be deployed so as to obtain a corresponding file to be deployed.
In one embodiment, the executing the corresponding operation according to the preset item type to be deployed to obtain the corresponding file to be deployed includes:
if the item type to be deployed is deployment, acquiring a preset configuration parameter of source code management in the item parameters;
pulling codes to be deployed from a preset code bin according to the preset configuration parameters;
and calling a preset coding tool to compile the code to be deployed to obtain a new file to be deployed.
In one embodiment, before the pulling the code to be deployed from the preset code bin according to the preset configuration parameters, the method further includes:
calling a first python script, and backing up a file which is deployed in the jenkins service for the last time through the first python script to obtain a backup deployment file;
and storing the backup deployment file according to a preset path to realize subsequent rollback calling.
In one embodiment, the executing the corresponding operation according to the preset item type to be deployed to obtain the corresponding file to be deployed includes:
if the item type to be deployed is rollback, obtaining rollback version parameters;
and obtaining the backup file to be deployed corresponding to the rollback version parameter through a second python script according to the rollback version parameter.
In one embodiment, the obtaining, according to the rollback version parameter, the backup to-be-deployed file corresponding to the rollback version parameter through a second python script includes:
acquiring a storage path of a corresponding backup deployment file according to the rollback version parameter;
and replacing the storage path of the file to be deployed of the automatic interaction channel with the storage path of the backup deployment file, wherein the backup deployment file under the storage path is the backup file to be deployed.
In one embodiment, the establishing an automatic interaction channel between the first server and the second server includes:
acquiring environment configuration parameters to be deployed;
and calling an expect script, and establishing an automatic interaction channel between the first server and the second server according to the environment configuration parameters through the expect script.
In one embodiment, the sending the file to be deployed to the second server through the automatic interaction channel includes:
and establishing the first automatic interaction and sending the file to be deployed.
In one embodiment, the responding to the task restart of the second server, the file to be deployed starts running, including:
establishing a second automatic interaction, and triggering the task of the second server to restart;
and responding to the task restart, and starting the file to be deployed to run.
In one embodiment, the method further comprises:
a jenkins service of the first server is constructed.
In one embodiment, said building a jenkins service of said first server comprises:
creating an item in the jenkins service;
and configuring the project parameters and configuring an execution script.
The technical scheme provided by the invention has at least one or more of the following beneficial effects:
in the technical scheme of implementing the invention, the project deployment task of the second server is realized by establishing the automatic interaction channel and setting according to project parameters, and meanwhile, the deployed file can be operated by completing the restarting task through the automatic interaction channel. The automatic deployment flow can reduce the time of repeated operation and the possibility of errors, thereby improving the deployment efficiency; and the risk of human errors can be reduced, and the accuracy and stability of deployment are ensured.
Further, automatic interaction between the two servers is realized by setting an expect script; by setting the python script, the backup and rollback call of the deployment file are realized, so that the scheme is more flexible to adjust, and the deployment flow can be adjusted at any time according to the requirement. The combination setting of the expect script and the python script enables the results of deployment under different environments to be the same, and reduces the influence of environment change on the running stability of the program. The Jenkins service, in combination with the expect script and the python script, manages and tracks the deployment process more conveniently by using integration tools and flows, and knows the status and results of each stage, thereby better controlling and adjusting the deployment strategy.
Drawings
The present disclosure will become more readily understood with reference to the accompanying drawings. As will be readily appreciated by those skilled in the art: the drawings are for illustrative purposes only and are not intended to limit the scope of the present invention. Moreover, like numerals in the figures are used to designate like parts, wherein:
FIG. 1 is a flow chart of the main steps of a jenkins-based project automatic deployment method according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating main steps of a method for obtaining a corresponding to-be-deployed file if the to-be-deployed item type is deployment according to an embodiment of the present invention;
FIG. 3 is a flow chart illustrating the main steps of a method for backing up deployment files before pulling code to be deployed according to one embodiment of the present invention;
FIG. 4 is a flowchart illustrating main steps of a method for obtaining a corresponding to-be-deployed file if the to-be-deployed item type is rollback according to an embodiment of the present invention;
FIG. 5 is a flow chart of the main steps of a method for obtaining a backup to-be-deployed file via a second python script according to one embodiment of the present invention;
FIG. 6 is a flow chart of the main steps of a method for establishing an automatic interaction channel between a first server and a second server according to one embodiment of the present invention;
fig. 7 is a flow chart illustrating main steps of a jenkins service method for constructing the first server according to an embodiment of the present invention.
Detailed Description
Some embodiments of the invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are merely for explaining the technical principles of the present invention, and are not intended to limit the scope of the present invention.
In the description of the present invention, a "module," "processor" may include hardware, software, or a combination of both. A module may comprise hardware circuitry, various suitable sensors, communication ports, memory, or software components, such as program code, or a combination of software and hardware. The processor may be a central processor, a microprocessor, an image processor, a digital signal processor, or any other suitable processor. The processor has data and/or signal processing functions. The processor may be implemented in software, hardware, or a combination of both. Non-transitory computer readable storage media include any suitable medium that can store program code, such as magnetic disks, hard disks, optical disks, flash memory, read-only memory, random access memory, and the like. The term "a and/or B" means all possible combinations of a and B, such as a alone, B alone or a and B. The term "at least one A or B" or "at least one of A and B" has a meaning similar to "A and/or B" and may include A alone, B alone or A and B. The singular forms "a", "an" and "the" include plural referents.
Referring to fig. 1, fig. 1 is a schematic flow chart of main steps of a project automatic deployment method based on jenkins according to an embodiment of the present invention. As shown in FIG. 1, the following steps S10-S40 are mainly included.
S10, acquiring files to be deployed related to project parameters constructed by jenkins service in a first server, wherein the files to be deployed are newly built files to be deployed or backup files to be deployed, and the backup files to be deployed are backed up before the newly built files to be deployed are newly built.
In this embodiment, the jenkins service and related plug-ins are installed in the first server. The jenkins service is a tool capable of automating software development, and related plug-ins can assist the operation of the jenkins service. The project automatic deployment method of jenkins is completed by shell script execution. According to project parameters constructed by the jenkins service, obtaining a to-be-deployed file related to the project parameters, wherein the to-be-deployed file can be a newly-built to-be-deployed file or a backup to-be-deployed file, the newly-built to-be-deployed file is a new version to-be-deployed file, and the backup to-be-deployed file is an old version to-be-deployed file, namely a deployed file which is deployed before and can be used for operating the version well.
In one embodiment, the obtaining the file to be deployed related to the project parameters constructed by the jenkins service in the first server includes step S11:
s11, executing corresponding operation according to the preset item type to be deployed so as to obtain a corresponding file to be deployed.
In this embodiment, the types of the items to be deployed preset are different, and the files to be deployed and the corresponding acquisition channels to be deployed are also different. Among the common project deployment types are deployment (delop) and rollback (rollback). The item deployment type is deployment, which means that a new version of item files needs to be deployed, and the item deployment type is rollback, which means that an old version of item files is deployed. The deployment situation occurs in the case of innovation or improvement of projects, and the like, namely, a new version of deployment file needs to be deployed; the rollback condition is that the deployed file cannot normally operate, and then the project file of the old version which normally operates needs to cover the current deployed file version, so that the project can normally operate.
In a specific embodiment, as shown in fig. 2, the step of executing the corresponding operation according to the preset item type to be deployed to obtain the corresponding file to be deployed includes steps S111-S113:
s111, if the item type to be deployed is deployment, acquiring a preset configuration parameter of source code management in the item parameters;
s112, pulling codes to be deployed from a preset code bin according to the preset configuration parameters;
s113, calling a preset coding tool to compile the code to be deployed to obtain a new file to be deployed.
In this embodiment, the type of the deployed project is deployment, that is, a project file of a new version needs to be deployed, and in source code management of project parameters, a code to be deployed is set to be pulled from which corresponding minute in which code warehouse needs to be deployed. Specifically, a git code repository is employed. After the code pulling is completed, compiling the code to be deployed through a preset coding tool to obtain a new file to be deployed. Specifically, the compiling operation of the code to be deployed is realized by configuring and calling Maven top-level calling parameters in the construction.
In one embodiment, as shown in fig. 3, before the pulling the code to be deployed from the preset code library according to the preset configuration parameters, the method includes steps S100-S101:
s100, calling a first python script, and backing up a file deployed in the jenkins service in the last time through the first python script to obtain a backup deployment file;
s101, storing the backup deployment file according to a preset path to realize subsequent rollback calling.
In this embodiment, the establishment and automatic deployment of the files to be deployed are implemented through the jenkins service, where the last deployed files remaining in the jenkins service need to be backed up and saved before a new project is established. The last deployed file that the backup kept at this time is a version that can be used normally and that works well. And carrying out backup storage on the residual item through a preset path according to parameters such as the type of the residual item and the like to obtain a backup deployment file. When the new version cannot normally run, the old version, namely the backup deployment file, can be called to be redeployed and run.
An example of a first python script that can be embodied for backup is provided herein, specifically including:
import os
import shutil
path = os.path.join(os.environ['WORKSPACE'], 'scfbi-admin', 'bak', '{}{}'.format(os.environ['env'], os.environ['BUILD_NUMBER']))
if not os.path.exists(path):
os. makedirs (path) # create folders, backup directories
shutil.copy2(os.path.join(os.environ['WORKSPACE'],'scfbi-admin','target', 'scfbi-admin-0.0.1-SNAPSHOT.jar'), path)
print ("bfwc |") # places the backup file under the corresponding directory
In this embodiment, WORKSPACE refers to an environment variable, commonly used in the jenkins service, representing the path of jenkins WORKSPACE. jenkins can store project source code, build results, etc. under this directory, where it is used to store backup files. Firstly defining and determining a backup path, judging whether the defined backup path exists or not, if not, creating a folder under the corresponding directory path, and backing up a file (jar package type file) to be backed up under the corresponding directory path.
In one embodiment, as shown in fig. 4, the performing a corresponding operation according to a preset item type to be deployed to obtain a corresponding file to be deployed includes steps S121-S122:
s121, if the item type to be deployed is rollback, obtaining rollback version parameters;
and S122, obtaining the backup file to be deployed corresponding to the rollback version parameter through a second python script according to the rollback version parameter.
In this embodiment, if the item type to be deployed is rollback, that is, the old version item file needs to be deployed, at this time, the rollback version parameter needs to be acquired. And obtaining the backup file to be deployed through the second python script according to the rollback version parameter.
Further, as shown in fig. 5, step S122 of obtaining, according to the rollback version parameter, a backup to-be-deployed file corresponding to the rollback version parameter through a second python script includes steps S1221-S1222:
s1221, according to the rollback version parameters, obtaining storage paths of corresponding backup deployment files;
s1222, replacing the storage path of the file to be deployed of the automatic interaction channel with the storage path of the backup deployment file, wherein the backup deployment file in the storage path is the backup file to be deployed.
In this embodiment, the storage path of the corresponding backup deployment file can be obtained according to the rollback version parameter, and the storage path of the file to be deployed of the automatic interaction channel is replaced by the storage path of the backup deployment file, and at this time, the backup deployment file becomes the backup file to be deployed. The automatic interaction channel can find the backup files to be deployed according to the changed path and send the backup files to be deployed to realize deployment.
An example is given herein in which a second python script can be embodied, which is primarily intended to replace a previously backed up file (i.e., a rollback version) with a current file to complete the rollback operation. The os, glob and share modules in the python standard library are used to complete file operations. The method specifically comprises the following steps:
import os
import glob
import shutil
#
files = glob.glob("scfbi-admin-0.0.1-SNAPSHOT.jar")
os.chdir('/home/app/.jenkins/workspace/Test/bbxt/scfbi-admin/target/')
file_count = len(files)
print(files)
if files != 0:
files = glob.glob("scfbi-admin-0.0.1-SNAPSHOT.jar")
for file in files:
os.remove(file)
print('del success')
path = os.path.join(os.environ['WORKSPACE'], 'scfbi-admin', 'bak', '{}{}'.format(os.environ['env'], os.environ['rollbackversion']))
os.chdir(path)
for file in os.listdir(path):
if file.endswith("scfbi-admin-0.0.1-SNAPSHOT.jar"):
src_path = os.path.abspath(file)
dest_path = os.path.join(os.environ['WORKSPACE'], 'scfbi-admin', 'target', file)
shutil.copy2(src_path, dest_path)
print('rb success')
in this embodiment, the above description is generally made herein, in which a file list named as "scfbi-admin-0.0.1-snappshot. Jar" in the current directory is obtained after a required module is imported, and assigned to the variable files; and calculating the length (the number of files) of the files list, assigning the length to the file_count variable, and outputting the files list. It is determined whether the file list is empty (i.e., whether there are files that need to be rolled back). If the files list is not empty, acquiring a 'scfbi-admin-0.0.1-SNAPSHOT.jar' file again; and constructing a path of the backup file according to the environment variable, and switching to the path. Traversing all files under the path to find a file ending with scfbi-admin-0.0.1-SNAPSHOT. Jar; acquiring an absolute path of a file, and constructing a target path; copying the file from the source path to the target path; and outputting prompt information of successful rollback.
S20, establishing an automatic interaction channel between the first server and the second server.
In one embodiment, as shown in FIG. 6, step S20 includes steps S21-S22:
s21, acquiring environment configuration parameters to be deployed;
s22, calling an expect script, and establishing an automatic interaction channel between the first server and the second server according to the environment configuration parameters through the expect script.
In this embodiment, the environmental parameter to be deployed includes related information of the second server, and a self-service interaction channel between the first server and the second server is established through the related information. The environment parameters to be deployed include, but are not limited to, a second server IP address, a second server user name, and a second server login password. The IP address may determine which second server is, and remote login may be implemented according to the user name and password to implement deployment of the project. The expect script is mainly used for automating the operation of the interactive application, i.e. for automating the file transfer and the command on the remote server, including connecting to the server, transferring files, executing remote commands, etc. The service deployment process can be automatically executed, so that manual intervention is reduced, and the error rate is reduced.
Further, the backup portion is performed by the first python script; the rollback portion is completed by the second python script execution; the automatic interaction establishing part is completed by executing an expect script, and different script execution is completed for different execution tasks, so that the deployment flow can be adjusted at any time according to requirements, and the flexibility is improved. In addition, when the deployment process is in a state, the problems can be found more quickly, the maintenance cost of a system administrator is reduced, and the labor cost is reduced. Meanwhile, the first python script and the second python, expect script are all called and executed by the shell script, so that the same deployment result under different environments can be ensured, and the reliability is improved.
S30, the file to be deployed is sent to a second server through the automatic interaction channel;
in one embodiment, the sending the file to be deployed to the second server through the automatic interaction channel includes:
and establishing the first automatic interaction and sending the file to be deployed.
And S40, responding to the restarting of the task of the second server, and starting the file to be deployed to run.
In one embodiment, the file to be deployed starts running in response to the task restart of the second server, including steps S41-S42:
s41, establishing a second automatic interaction, and triggering the restarting of the task of the second server;
s42, responding to the task restart, and starting the file to be deployed to run.
In this embodiment, a shell script located at the second server is triggered, and restarting of the shell script enables a file newly deployed to the second server to run. Two automatic interactions are established through the expect script, the first automatic interaction is used for sending the files to be deployed to the second server, and the second automatic interaction is used for logging in the account to realize the starting operation of the files to be deployed.
Specifically, an example of an aspect script that can be specifically implemented is given herein, including:
set timeout 3 # initialization latency of 3 seconds
set host [ lindex$argv0 ] # set the first variable parameter
set username "app" # sets the value of the parameter username
set password "app" # sets the value of parameter password
if { $host= = "test" } { # determine whether the host parameter is test
set hosts "22.50.5.75" # set connection server ip
sleep # 1 waits 1 second
After the Spawn scp# establishes the connection, the cp file/home/app/. Jenkins/workspace/Test/bbxt/scfbi-admin/target/scfbi-admin-0.0.1-SNAPSHOT.jar @ $ hosts:/home/app/bbx# transmits the file to the 22.50.5.75 server
# where timeout is 3 seconds, the next match is performed over three seconds
expect "/no" { send "yes\r" } # default to select yes and execute
expect ". Password" { send "$password\r" } # acquires the parameter password and executes it
# when the scp transfers a file, the timeout time is set to infinity, and when a large file is transferred, more time is required
set timeout 20
# when matching to transfer completion 100%, go to the next step
expect "100%"
Use eof ends the process because the above sets timeout to-1 Infinite
The timeout time was set to 3 seconds.
The spawn ssh $username@ $hosts# obtains the user name and ip of the connection server
expect ". Password" { send "$password\r" } # obtains the password and inputs it
sleep 3 # waits three seconds
send "cd bbxt\r" # is executed at 22.50.5.75 server
sleep # 1 waits 1 second
send "sh start. Sh restart\r" # execute shell script
sleep # 5 waits 5 seconds
expect eof # close connection
In this embodiment, the expect script is used to automatically execute the file transfer and the commands on the remote server, including connecting to the server, transferring the file, executing the remote commands, etc., and the above-mentioned expect script is briefly described herein: setting the timeout time to 3 seconds; set variables host, username and password, respectively representing a host name, a user name and a password; obtaining and setting the IP address of the server as 22.50.5.75 through the mapping relation; invoking the scp command using the spin command to transfer the specified file to the server; wait for a particular string to appear using the expect command, and send "yes\r" if "yes/no" appears. If the password appears, sending the password; setting a timeout time of 20 seconds so that there is enough time to transfer a large file; when the transmission is 100% complete, the next step is continued. The first automatic interaction is completed, and the file transmission to be deployed is completed. Acquiring a user name and an IP (Internet protocol) of a connection server; waiting for a password prompt, and then sending a password; waiting for 3 seconds, and sending a 'cd bbxt\r' command to be executed by a 22.50.5.75 server; waiting for 1 second, and sending a 'sh start, sh restart\r' to execute a restart command; wait 5 seconds and end the connection. The file to be deployed for executing the restart command can realize that the deployment operation is the second automatic interaction.
In one embodiment, the method further comprises: a jenkins service of the first server is constructed. As shown in fig. 7, the jenkins service of the first server is constructed specifically including steps S01-S02:
s01, creating an item in the jenkins service;
s02, configuring the project parameters and configuring an execution script.
In this embodiment, multiple types of items can be created in the jenkins service, and item items need to be created in this application. Further, parameters are configured for the content under the General, source code management, construction triggers, construction environment, construction and other project bars in a visual interface. Wherein, the General project column is configured with a Choose Parameter, a String Parameter, a Git Parameter and the like; configuring a git code warehouse, a default pull branch and the like by a source code management project column; constructing a configuration polling SCM under a trigger project bar and the like; setting up Set Build Name, add timestamps to the Console Output and the like under the construction environment project column; the under-project-bar configuration call Maven top-level call parameter is constructed, and the execution shell script (i.e. the program flow of what script is called under what condition by the shell script) is configured. Wherein configuring the polling SCM in the build trigger configuration enables real-time detection of changes in the git code repository. When the change of codes in the git code warehouse is detected, triggering a project deployment task, reading parameters according to the set project parameters, calling a corresponding script (such as a first python script) according to the parameters, executing corresponding operations (such as backup), and completing execution according to the setting of the shell script so as to realize an automatic project deployment flow.
Furthermore, the shell script is adopted for the operation of the jenkins service, namely, the preset parameters are obtained and corresponding operation commands are executed by calling the first python script, the second python script and the expect script through configuration of the shell script. Examples of partially implementable shell scripts are given herein:
when the type to be deployed is deployment (deployment):
echo "Status: $status" # acquires parameters and outputs them
echo-e "\θ33[46 ]; 30m release type $Status\θ33θm# obtain parameters and output
echo-e "\θ33[46 ]; 30m compilation Environment $env\θ33[ θm "# obtains parameters and outputs
cd ${WORKSPACE}
cd /home/app/python
The first python script is executed to realize backup by the python bbxt.py# backup package
expect/home/app/shell/bbxt. Exp$env# executing expect script
When the type to be deployed is rollback (rollback):
echo "Status: $status" # acquires parameters and outputs them
echo-e "\033[46, 30m release type $Status\033 [0m" # get parameters and output
echo-e "\033[46, 30m rollback version $env- $rollbackversion \033[0m" # acquires parameters and outputs
echo "rollback version: $rollback version" # acquires parameters and outputs
cd $ { WORKSACACCE }/scfbi-admin/target# to the corresponding directory
The python/home/app/python/bbxt_roll. Py# call executes the second python script
The expect/home/app/shell/bbxt_roll.exp$env# call executes the expect script
In the technical scheme of implementing the invention, the project deployment task of the second server is realized by establishing the automatic interaction channel and setting according to project parameters, and meanwhile, the deployed file can be operated by completing the restarting task through the automatic interaction channel. The automatic deployment flow can reduce the time of repeated operation and the possibility of errors, thereby improving the deployment efficiency; and the risk of human errors can be reduced, and the accuracy and stability of deployment are ensured.
Further, automatic interaction between the two servers is realized by setting an expect script; by setting the python script, the backup and rollback call of the deployment file are realized, so that the scheme is more flexible to adjust, and the deployment flow can be adjusted at any time according to the requirement. The combination setting of the expect script and the python script enables the results of deployment under different environments to be the same, and reduces the influence of environment change on the running stability of the program. The deployment process is managed and tracked more conveniently by using the integrated tools and processes, and the state and the result of each stage are known, so that the deployment strategy is controlled and adjusted better, and quick, reliable and automatic deployment can be realized.
It should be noted that, although the foregoing embodiments describe the steps in a specific order, it will be understood by those skilled in the art that, in order to achieve the effects of the present invention, the steps are not necessarily performed in such an order, and may be performed simultaneously (in parallel) or in other orders, and these variations are within the scope of the present invention.
It will be appreciated by those skilled in the art that the present invention may implement all or part of the above-described methods according to the above-described embodiments, or may be implemented by means of a computer program for instructing relevant hardware, where the computer program may be stored in a computer readable storage medium, and where the computer program may implement the steps of the above-described embodiments of the method when executed by a processor. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable storage medium may include: any entity or device, medium, usb disk, removable hard disk, magnetic disk, optical disk, computer memory, read-only memory, random access memory, electrical carrier wave signals, telecommunications signals, software distribution media, and the like capable of carrying the computer program code. It should be noted that the computer readable storage medium may include content that is subject to appropriate increases and decreases as required by jurisdictions and by jurisdictions in which such computer readable storage medium does not include electrical carrier signals and telecommunications signals.
Further, it should be understood that, since the respective modules are merely set to illustrate the functional units of the apparatus of the present invention, the physical devices corresponding to the modules may be the processor itself, or a part of software in the processor, a part of hardware, or a part of a combination of software and hardware. Accordingly, the number of individual modules in the figures is merely illustrative.
Those skilled in the art will appreciate that the various modules in the apparatus may be adaptively split or combined. Such splitting or combining of specific modules does not cause the technical solution to deviate from the principle of the present invention, and therefore, the technical solution after splitting or combining falls within the protection scope of the present invention.
The personal information of the relevant user possibly related in each embodiment of the application is personal information which is strictly required by laws and regulations, is processed actively provided by the user in the process of using the product/service or is generated by using the product/service and is obtained by authorization of the user according to legal, legal and necessary principles and based on reasonable purposes of business scenes.
The personal information of the user processed by the applicant may be different according to the specific product/service scenario, and may relate to account information, equipment information or other related information of the user, depending on the specific scenario in which the user uses the product/service. The applicant would treat the user's personal information and its processing with a high diligence.
The applicant has very important consideration to the safety of personal information of users, and has adopted safety protection measures which meet industry standards and are reasonably feasible to protect the information of the users and prevent the personal information from unauthorized access, disclosure, use, modification, damage or loss.
Thus far, the technical solution of the present invention has been described in connection with the preferred embodiments shown in the drawings, but it is easily understood by those skilled in the art that the scope of protection of the present invention is not limited to these specific embodiments. Equivalent modifications and substitutions for related technical features may be made by those skilled in the art without departing from the principles of the present invention, and such modifications and substitutions will fall within the scope of the present invention.

Claims (10)

1. The project automatic deployment method based on jenkins is executed by a shell script and is characterized by comprising the following steps of:
acquiring a file to be deployed related to project parameters constructed by jenkins service in a first server, wherein the file to be deployed is a newly built file to be deployed or a backup file to be deployed, and the backup file to be deployed is obtained by backup before the newly built file to be deployed is newly built;
establishing an automatic interaction channel between the first server and the second server;
sending the file to be deployed to a second server through the automatic interaction channel;
and responding to the task restarting of the second server, and starting the file to be deployed to run.
2. The method of claim 1, wherein the obtaining the to-be-deployed file associated with project parameters of the jenkins service build in the first server comprises:
and executing corresponding operation according to the preset item type to be deployed so as to obtain a corresponding file to be deployed.
3. The method according to claim 2, wherein the performing the corresponding operation according to the preset item type to be deployed to obtain the corresponding file to be deployed includes:
if the item type to be deployed is deployment, acquiring a preset configuration parameter of source code management in the item parameters;
pulling codes to be deployed from a preset code bin according to the preset configuration parameters;
and calling a preset coding tool to compile the code to be deployed to obtain a new file to be deployed.
4. The method according to claim 2, wherein the performing the corresponding operation according to the preset item type to be deployed to obtain the corresponding file to be deployed includes:
if the item type to be deployed is rollback, obtaining rollback version parameters;
and obtaining the backup file to be deployed corresponding to the rollback version parameter through a second python script according to the rollback version parameter.
5. The method of claim 4, wherein obtaining, according to the rollback version parameter, a backup to-be-deployed file corresponding to the rollback version parameter via a second python script, comprises:
acquiring a storage path of a corresponding backup deployment file according to the rollback version parameter;
and replacing the storage path of the file to be deployed of the automatic interaction channel with the storage path of the backup deployment file, wherein the backup deployment file under the storage path is the backup file to be deployed.
6. The method of claim 1, wherein the establishing an automatic interaction channel between the first server and the second server comprises:
acquiring environment configuration parameters to be deployed;
and calling an expect script, and establishing an automatic interaction channel between the first server and the second server according to the environment configuration parameters through the expect script.
7. The method of claim 1, wherein the sending the file to be deployed to a second server through the automated interaction channel comprises:
and establishing the first automatic interaction and sending the file to be deployed.
8. The method of claim 1, wherein the file to be deployed initiates execution in response to a task restart of the second server, comprising:
establishing a second automatic interaction, and triggering the task of the second server to restart;
and responding to the task restart, and starting the file to be deployed to run.
9. The method according to claim 1, wherein the method further comprises:
a jenkins service of the first server is constructed.
10. The method of claim 9, wherein said building a jenkins service for said first server comprises:
creating an item in the jenkins service;
and configuring the project parameters and configuring an execution script.
CN202310671357.1A 2023-06-08 2023-06-08 Project automatic deployment method based on jenkins Active CN116400934B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310671357.1A CN116400934B (en) 2023-06-08 2023-06-08 Project automatic deployment method based on jenkins

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310671357.1A CN116400934B (en) 2023-06-08 2023-06-08 Project automatic deployment method based on jenkins

Publications (2)

Publication Number Publication Date
CN116400934A true CN116400934A (en) 2023-07-07
CN116400934B CN116400934B (en) 2023-09-15

Family

ID=87018391

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310671357.1A Active CN116400934B (en) 2023-06-08 2023-06-08 Project automatic deployment method based on jenkins

Country Status (1)

Country Link
CN (1) CN116400934B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370483A (en) * 2023-12-06 2024-01-09 金云数据科技有限公司 Automatic BIM model release service method based on python

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109800006A (en) * 2018-12-28 2019-05-24 易票联支付有限公司 A kind of dissemination method, system and storage medium customizing script
CN111338644A (en) * 2020-02-28 2020-06-26 深圳壹账通智能科技有限公司 Task script deployment method and system
CN112764753A (en) * 2020-12-31 2021-05-07 北京知因智慧科技有限公司 Project deployment method and device, electronic equipment and storage medium
CN112860251A (en) * 2019-11-12 2021-05-28 中科曙光南京研究院有限公司 Method and system for constructing website front end
US11157253B1 (en) * 2020-06-30 2021-10-26 Td Ameritrade Ip Company, Inc. Computer-automated software release and deployment architecture
US20230019705A1 (en) * 2021-07-06 2023-01-19 Servicenow, Inc. Centralized Configuration Data Management and Control

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109800006A (en) * 2018-12-28 2019-05-24 易票联支付有限公司 A kind of dissemination method, system and storage medium customizing script
CN112860251A (en) * 2019-11-12 2021-05-28 中科曙光南京研究院有限公司 Method and system for constructing website front end
CN111338644A (en) * 2020-02-28 2020-06-26 深圳壹账通智能科技有限公司 Task script deployment method and system
US11157253B1 (en) * 2020-06-30 2021-10-26 Td Ameritrade Ip Company, Inc. Computer-automated software release and deployment architecture
CN112764753A (en) * 2020-12-31 2021-05-07 北京知因智慧科技有限公司 Project deployment method and device, electronic equipment and storage medium
US20230019705A1 (en) * 2021-07-06 2023-01-19 Servicenow, Inc. Centralized Configuration Data Management and Control

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
于红雨;李燕;: "Windows平台的软件自动构建与发布技术研究", 成组技术与生产现代化, no. 02 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370483A (en) * 2023-12-06 2024-01-09 金云数据科技有限公司 Automatic BIM model release service method based on python
CN117370483B (en) * 2023-12-06 2024-03-08 金云数据科技有限公司 Automatic BIM model release service method based on python

Also Published As

Publication number Publication date
CN116400934B (en) 2023-09-15

Similar Documents

Publication Publication Date Title
CN107729066B (en) Automatic construction and release method and device based on SVN (singular value decomposition) resource library
CN108830720B (en) Intelligent contract running method, device, system and computer readable storage medium
KR101802920B1 (en) Method and apparatus for creating a virtual machine system disk snapshot
KR100442884B1 (en) Method for updating firmware
US10956270B2 (en) System and method for data protection during full data backup
US20160179495A1 (en) Device and method for packaging application
EP3435235A1 (en) Method and device for executing data recovery operation
CN116400934B (en) Project automatic deployment method based on jenkins
US11106451B2 (en) Automated software package deployment
CN108121543B (en) Software code compiling processing method and device
CN103984573A (en) Installation method and device of application program
US20100235482A1 (en) Virtual Appliance Automation Tool
CN110262873B (en) Configuration modification method and device for container application, computer equipment and storage medium
CN110225078B (en) Application service updating method, system and terminal equipment
CN111162953B (en) Data processing method, system upgrading method and server
CN112953983A (en) SFTP transmission method and device
CN111651352B (en) Warehouse code merging method and device
CN108132832B (en) Application program starting method and device
CN106020855A (en) Multiple CPU system and method for upgrading CPU
CN106970865B (en) Monitoring and management of software as a service in a micro-cloud environment
CN111897565A (en) Data processing method, device and equipment based on Internet of things
JP5147859B2 (en) Apparatus and method for protecting and recovering stored data
CN115599399A (en) Application program deployment method and device and storage medium
GB2515598A (en) Information processing apparatus and information processing method
US11528185B1 (en) Automated network device provisioning

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant