Basic environment
- Operating system: Linux version 5.10.60-9.al8.x86_64 ([email protected]) (GCC (GCC) 10.2.1 20200825 (Alibaba 10.2.1-3) 2.30)
- The JDK: jdk1.8.0 _131
- Vue: 2.6.10
- Jenkins: 2.319.3
Jenkins installation
- Backup official default update source files
sudo wget -O /etc/yum.repos.d/jenkins.repo <http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo>
Copy the code
- Import the GPG key
sudo rpm --import <https://jenkins-ci.org/redhat/jenkins-ci.org.key>
Copy the code
- The installation
sudo yum install jenkins
Copy the code
- View jekins service status
systemctl status jenkins.serve
Copy the code
Modify the configuration
- port
Jekins default is port 8080 project 8080 has other services to use here to use 8010 to enable port 8010 in Ali Cloud in advance
- Modify the configuration to /etc/sysconfig/jenkins
Vim /etc/sysconfig/jenkins # JENKINS_USER="root"JENKINS_PORT="8010"
Copy the code
- Adding Java paths
Run the Java /etc/init.d/ Jenkins command to run the Java /etc/init.d/ Jenkins command"/ usr/local/Java/jdk1.8.0 _131 / bin/Java"
Copy the code
Start the
systemctl start jenkins
Copy the code
access
2. Configure domain name access. Add Jekins configuration under nginx configuration
/etc/nginx/conf.d/ # /etc/nginx/confCopy the code
- Jenkins configuration
server {
listen 80; # server_name jekins.test.aggie.cn; charset utf-8; Location /{# Locate to the machine8010Proxy_pass HTTP:/ / 127.0.0.1:8010;proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass_request_headers on; }}Copy the code
- Enter http://ip:8010, IP: external IP address of the server, for example, 47.16.24.xxx-8888. Domain name: jekins.test.aggie.cn
- The Jekins initial page appears
You will be prompted to enter the administrator password later
vi /var/lib/jenkins/secrets/initialAdminPassword
Copy the code
Copy the password and fill in the page to enter Jekins
Installing a plug-in
- Installing recommended plug-ins (time-consuming and sometimes failed)
2. Create an administrator account
3. Configuration instance (after saving, it will enter jekins management page)
Configuration items
- Because the project will be deployed on different servers, some plug-ins will need to be installed
- Check whether Git is installed on the server
which git
Copy the code
After installation, the following image will appear2. Install Git Parameter plug-in NodeJS
Git Parameter plug-in can be selected to build Git branch. Node JS is used to execute NPM script 3 install Publish over SSH to build complete push remote server
Build this server
A new task
The project name
Enter the project name click Build a free style software project and click OK
Configure project build parameters (set different branch releases)
Git Parameter is a branch or tag that can be used to build Git
Source code management
- Select Git and enter the corresponding project’s address
- Add Jekins credentials to pull gitLab code
- Add credential select Global credential type there are many different options so I’m going to select account and password
Then enter the username and password (id and description can be omitted) and click Add
- Select the credentials you just added
- Adding branches to Build I’ve added two here to select different branch builds
Build environment
- Select Provide Node & NPM bin/ Folder to PATH (the plug-in already has Nodejs installed)
- Select node Configuration
build
- Select execute shell here
- Enter the corresponding script
npm install
rm -rf ./dist/* npm run build:prod rm -rf /pms-web/web/dist cp -rf ./dist /pms-web/web/Copy the code
NPM install Installs dependencies
Rm -rf./dist/* Clear the project dist folder
NPM run build:prod executes the VUE project build
Rm -rf /pms-web/web/dist Clear the dist folder on the server
Cp-rf./dist/PMS -web/web/ Copy and paste the packaged project to the specified path on the server
Click save
Project initialization
Go back to the task list and you’ll see the task we created
Click into the project
Click on workspace now workspace is empty and you need to build it again
Click Build with Parameters
Will let us choose the corresponding branch to build
Choosing branches to build will be slow on the first build
We can see the build process through the build history
At this point, our workspace is already empty
Push the remote server
Because of the project we need to deploy the code to another server and at this point we installed the plugin Publish over SSH to do the remote server push new task and the process is the same as above. Now let’s look at pushing the code to another server
Configure Publish over SSH
1. Choose System Management > System Configuration
- Go to Publish over SSH and click the Add button
3. Configure the remote server
- Name Name yourself
- Hostname Specifies the server address
- Username username for connecting to the server
- Remote Directory Specifies the Directory on the server to be located
Click Advanced Password after the configuration is complete
- Port 22 is used to write Proxy Password
- And then SAVE
Configuration items
The new task is the same as before and finally we’re going to configure the remote server area build which is essentially putting the local DIST on another server
- Enter the task and click Settings
- Just create the install dependency Build project in the build section
Then select the post-build project and click Add Serve
Select the service you just created in SSH Server Name
Then configure the location of the project on the server
- Source files Directory for packing files
- Remove prefix whether to delete dist only copy the files in the folder according to the nginx configuration
- Remote directory Specifies the directory where the server project is stored according to the Nginx configuration
And I’m gonna hit Save
This allows you to deploy the project to the know server