In the past, we had to package the project manually and synchronize it to the server using FTP or other methods. This method was very cumbersome and inefficient, and was prone to environmental release errors. In order to solve these problems, we could use Jenkins to automate the release.
I am using CentOS 7.5, other systems will differ when installing the environment.
Jenkins releases workflow
- Native push code
- Jenkins on the server pulls the code
- Move the code to the Web services working directory
- Sending Email Notifications
To prepare
- Git repository (gitLab, Github, Code Cloud, or another Git repository with Web hooks)
- One server (Windows or Linux, using CentOS 7.5 64-bit)
- Git, Java, Jenkins installed on the server
Install the Java
yum install java
Copy the code
Verify that the installation is successful
java -version
Copy the code
If the version number is displayed, the installation is successful
Install git
yum install git
Copy the code
Verify that the installation is successful
git --version
Copy the code
Install Jenkins
Tip: Different operating systems download different packages, installation commands are different
-
Open the Jenkins. IO/useful/download… To select the installation file of the corresponding system
-
Installation (Run in the installation package directory)
Sudo RPM - ih Jenkins - 2.121.3-1.1 noarch. RPM
-
Start the
service jenkins start
If the startup succeeds, enter http://server address :8080 in the browser to access the portal page. If not, check whether port 8080 is used.
The cat on the server input/var/lib/Jenkins/secrets/initialAdminPassword check the administrator password, enter the password and then click the continue.
Then select the recommended plug-in to install and wait for the installation to complete
After the installation is complete, we click on the lower right corner to continue using the admin account
Then click Save and finish
Click Start Jenkins to jump to the home page
Create a task
Click Start To create a new task, enter a name, select Build a free style software project, and click OK
Configure source code management
- Click on the
Source code management
- choose
GIT
Repository URL
Fill in our Git repository address
Branches to build
Enter the branch we need to pull
Build configuration
After git is pulled, we need to copy the code to the directory of the Web service. Here we can use the sshell command to do the operation
- Click on the
build
- Click on the
Adding build steps
, the choice ofPerform sshell
- Enter the copy file command
cp -r ./dist/* /var/project/test
(Note the path and folder name, need to change your project path)
Then click Save. Now we can publish the project by clicking Build Now in the left menu.
Web hooks publish automatically
After submitting the code, open Jenkins and click Build. Next, we will implement git push code and automatically build
Install the Generic Webhook Trigger plug-in
- Go back to the home page and click
System management
->Plug-in management
- Click on the
Optional plug-in
Search,Generic Webhook Trigger
And then clickInstalled directly
- After installation, return to the home page, click the project name, and select
configuration
- Click on the
Build trigger
, the choice ofGeneric Webhook Trigger
- in
Token
Fill in a token (cannot be duplicated with other project tokens) and click Save
Git configuration hooks (add them in Settings on Github similarly)
- Go to the Git project page and choose Configuration > WebHook > Add
- in
URL
Fill in the addressYour Jenkins server address: port /generic-webhook-trigger/invoke? Configuration of the token
My address is my addresshttp://192.168.3.18:8080/generic-webhook-trigger/invoke?token=test-project
- Click Save, and then just
push
Jenkins will automatically publish the code
Email alerts
After the completion of the construction, send the result and log to the mailbox. Take QQ mailbox as an example, other mailboxes are similar
- in
jenkins
Search in plug-insEmail Extension Plugin
Install (if you can’t find it, go to install to check whether it has been installed) - When the installation is complete, go back to the home page and click
System management
->The system configuration
-
System administrator Email address: Enter the configured email address
-
Locate the Extended E-mail Notification option and fill in the following configuration
- SMTP server: indicates the SMTP address of the mailbox. The QQ mailbox is
smtp.qq.com
163 email issmtp.163.com
, other mailboxes can be searched by themselves - Default User E-mail suffix: indicates the mailbox suffix
- Click advanced in the lower right corner and fill in the following configuration
In the configuration, the User Name is your email, and the Password is your SMTP Password, which can be checked in the email Settings
- Default Content Type: Select this option
HTML(text/html)
- Default Recipients: Indicates the Default recipient
- SMTP server: indicates the SMTP address of the mailbox. The QQ mailbox is
-
After the configuration is complete, return to project Settings, select Post-Build operations, click Add Post-Build operations, and select Editable Email Notification
-
Fill in the Project Recipient List option with your notification email address
-
Attach Build Log Select Attach Build Log to send the email with the Build Log
-
Click Add Trigger and select Always and click Save
-
Click Save after configuration and then click Build Now to test whether our email notification can be sent successfully
At the end
At this point we have completed the automated release of Jenkins, but this is still a simple configuration, and I will continue to write about how to publish to remote servers. It is the environment and test environment that distinguish the Build release of Node and Golang.
Flutter – Weui is a library of Weui components that can be implemented with Flutter on Android and ios (web and desktop as well). There are more than 30 components that can be implemented with Flutter