Use jenkins automation package deployment Vue project. Detailed tutorial.

This tutorial jenkins is deployed directly to the linux server. Server systems: CentOS 7.3 64 bits.

Process: jenkins code associated with cloud storage, click on the building immediately, execute the shell to build, package, the package dist directory files onto the server, complete automation package deployment.

A server installed Java

jenkins is running in order to use the java environment, so you must install java, java configuration environment variable.

1, the unloading system comes with jdk
//查找系统jdk 
[root@VM_0_2_centos ~]#  rpm -qa|grep java 
java-1.6.0-openjdk-1.6.0.37-1.13.9.4.el5_11
tzdata-java-2015g-1.el5
//如果查找到了 先全部卸载了在重新安装

//卸载
[root@VM_0_2_centos ~]# rpm -e --allmatches --nodeps python-javapackages-3.4.1-11.el7.noarch
[root@VM_0_2_centos ~]# rpm -e --allmatches --nodeps tzdata-java-2019a-1.el7.noarch
[root@VM_0_2_centos ~]# rpm -e --allmatches --nodeps java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
[root@VM_0_2_centos ~]# rpm -e --allmatches --nodeps java-1.8.0-openjdk-headless-1.8.0.212.b04-0.el7_6.x86_64

//检查是否卸载干净
[root@VM_0_2_centos ~]#  rpm -qa|grep java 
复制代码
2, look at the list of yum renewable Java
yum -y list java*
//或者
yum search jdk
复制代码
3, install java
yum install -y java-1.8.0-openjdk.x86_64
//验证完成安装
java -version
复制代码
4, configure the environment variables

Open / etc / profile with a text editor

[root@VM_0_2_centos ~]# vi /etc/profile
复制代码

Join the end of the profile file:

export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
复制代码
//使配置文件生效
source /etc/profile 
source ~/.bash_profile
//或重启机器配置生效
reboot
复制代码

II. Server Installation jenkins

[root@VM_0_2_centos ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo 
[root@VM_0_2_centos ~]# yum install jenkins
//会询问你
Total download size: 74 M
Installed size: 74 M
Is this ok [y/d/N]: y
复制代码

Successful installation:

III. Start jenkins

Enter the browser HTTP: // ip: 8080 , ip: server outside the network ip address Example: 118.24.211.xxx:8080

And so after waiting to prompt you to enter the administrator password

//服务器
[root@VM_0_2_centos ~]# vi /var/lib/jenkins/secrets/initialAdminPassword

复制代码

Copy the contents of the input to the interface.

If this seems to have Jenkins instance goes offline.

Browser to access 118.24.211.xxx:8080/pluginManag...
modification

https instead http.

Sometimes I will run the Jenkins instance appears to be offline, sometimes does not appear. I do not know if a network problem. If it will appear https to http

Install plug

Click on the recommended installation, wait a moment, there will be

The installation of the plug-in will be more time-consuming little long. Wait patiently.

Create the first administrator user after installing the plug-in

Click Save and then fill out a form to complete

Continue to click Save and Finish

Click start using jenkinsthis time jenkinsit has been configured success.

IV. Used jenkinsto create a build task

Here I use the code repository cloud code (github is the same)
Enter the address of the warehouse. Because the warehouse is private so there will be error prompt where you want to add Credentials. Cloud is your code or github account.

Select the account error disappears

Here you can fill out to build a branch

This time it creates a build task
back to the Home ==> you will see a build task my_test

Point into ==>
Then click the workspace ==> nothing indicating that you need to build a work space will have.

Click immediately to build ==>

Click in the workspace ==>

jenkinsConstruction of the task has been completed

V. Fill jenkinsshell scripts to execute when building

Click Configuration ==>

Click the Add build step ==>

Click execute shell ==>

Enter the shell command ==>

npm install 
rm -rf ./dist/*
npm run build
rm -rf /www/web/site/*
cp -rf ./dist/* /www/web/site
复制代码

npm install: Download the workspace npm package
rm -rf ./dist/*: delete all files in the directory dist, dist directory is the current jenkinspost-workspace package files.
npm run build: performing a packing command
rm -rf / www / web / site / *: delete all the files on the server / www / web / site / directory / www / web / site / placement for the server project.
cp -rf ./dist/* / www / web / site: the current build workspace dist directory to copy a file server / www / web / site folder.

To return to my_test project.

Click now to build ==> to build discovered the error (red dot is the build fails, blue success)

Click to # 5 to enter the details of building ==>

Click on the console output ==>

Report to see what is wrong ==>

npm: command not found
复制代码

jenkins is not installed by default node plug, not all command npm
install plug-node ====>

Find NodeJS select the Install ===>

Successful installation ===>

Click Global Configuration Tools ===>

New nodeJs ===>
Save ===>
Back my_test configuration space click Build Environment ===>

Save ===>

Click back my_test space to build the first building will be immediately executed npm install download a lot of packages will be very slow

The building still failed to see the console output # 8 ===>

shell script execution, but not all successful.

When we installed on the server jenkins, it creates a jenkins user on the server. But this jenkins no operating authority / www / web / site folder

Jenkins user to add all permissions / www / web / site folder ===>

[root@VM_0_2_centos /]# chown -R jenkins:jenkins /www/web/site
复制代码

Back jenkinsmy_test space Click immediately to build ===>

The # 9 on the success of the open console output ===>

Finished: SUCCESS

VI. Open the server

View server / www / web / site / folder contents inside

/ Www / web / site / content which has been packaged after.

Create a site => Select / www / web / site / directory to complete the deployment of the project.


Reproduced in: https: //juejin.im/post/5d07558e5188251260274905

Guess you like

Origin blog.csdn.net/weixin_34007291/article/details/93162686