Linux installs Jenkins to automatically obtain code and package front-end code

Linux installs Jenkins to automatically obtain code and package front-end code

Jenkins

JenkinsIt is not a programming language, but just a tool, a tool written in java, so it needs an javaenvironment
to help us update the monitoring code and perform automated processes (such as packaging vue files, packaging react files, or back-end file compilation, etc.) )

The following steps were centos 7performed under ambient, the installation package using some yumsource. If you are using ubuntu or other linux distributions, you need to check it yourself~

Install Jenkins

  1. First check whether the java environment is in effect
java -verison

It just so happens that my java environment (openjdk)is 1.8.0

If you don’t have the java environment installed, you can read this detailed linux installation jdk1.8 tutorial
or directlyyum install java


  1. Add a mirror source (take centos as an example, ubuntu is similar, but the files are different, so you can distinguish by yourself~)
# 添加镜像源
sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo

# 导入公钥
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.k

After the addition is complete, use the yum command to install Jenkins:

yum install jenkins -y

The installation process is very long. When I installed it, the first installation failed because the network is too slow. If I can use the Internet scientifically~

The yum package is installed, but there is still a little episode, I don’t understand the reason, but if you encounter something like this: the public key of jenkins has not been installed

Then we are like this:

yum install jenkins -y --nogpgcheck
  • --nogpgcheck Means to skip the verification of the public key
  • The yum source has already downloaded the package once, so it is very fast to execute this again, and there is no need to wait repeatedly

  1. After the installation is complete,注意下配置在开始启动

Why should I emphasize this, because I don’t have to wait for the next set of procedures to find that the catalog is unreasonable, then it’s not fun~

Modify the configuration file:sodo vim /etc/sysconfig/jenkins

The important configuration talks about:

JENKINS_HOME="/var/lib/jenkins/"

JENKINS_USER="jenkins"

JENKINS_PORT="9999"
  • JENKINS_HOMEThe working area of ​​jenkins, the plug-ins installed later by jenkins, and the changed configuration are all in this directory. If there are strict requirements on the storage location of software files, change this path first,正常来说打包后的文件也会在这个目录下。也可以设置指定的目录,后面会讲

  • JENKINS_USERThe concept of user groups related to linux. Because to manage files, so when the owner of the file is to change jenkinsthe.

  • JENKINS_PORTThis default is port 8080. I changed it to 9999. Because my local port 8080 has long been used. After changing to 9999, remember to let the server's 9999 port be released, otherwise you won’t be able to access it


  1. Start service

There are only a few jenkins commands

effect command
start up service jenkins start
shut down service jenkins stop
Reboot service jenkins restart

run service jenkins start

See input

Then open the browser 192.168.0.166:9999,

  • Because my centos is a LAN machine, my ip is 192.168.0.166. If you are a cloud server, it should be your corresponding public IP
  • 9999 is because I changed the port 9999 in the configuration file. If it is not changed by default, it is 8080

The first time you open it, you need to enter the key. The
key is in the path in the red box in the figure.

cat /var/lib/jenkins/sec..... # (不想写了。好长)

Just copy it in


  1. Create users and install plugins

    • No need to say more when creating an account. Fill in, the next step
    • To install the plug-in, I use the plug-in recommended by default, after all, a novice is getting started
    • The network is not very good. I installed the plug-in for half an hour. I couldn't install some github plug-ins in the end, but I didn’t use github, so even if the installation failed, I skipped it~

  1. Install the corresponding environment

As mentioned earlier, if you want to package the vue project and package the react project, the premise is the node environment. There is no node in the recommended plugin. So we have to find the node plug-in by ourselves: as shown in the figure (this one is in Chinese and English, found in the sidebar)

Find nodejs. After installation, just restart


  1. Global configuration. Configure the node environment

The same is true for other environments, I won’t list them one by one, I’m just a small front end~


  1. Start creating the project!
  • Back to the home page, click New Item

  • Remember to choose Freestyle project custom project

  • Came to the configuration page. A total of

Talk a little bit~

general can't understand, pass~

Source Management >
fill in the address of the warehouse, the warehouse will see if it is private like me false alarms, below Credentialsyou can add a user account, or log in with ssh keys. Are the basis of the git
select the directory git code
if not checked, then went to the default /var/lib/juxxxxdirectory to go. Or it will pull the code into the working area of ​​the configuration file.

I still specify the local warehouse directory here:
> Execution branch The
default is master. It is to monitor the update of the master, if it is deleted. That is to monitor all branch updates, and then execute the build process

Build trigger

  • 触发远程构建 (例如,使用脚本) Never used~
  • Build after other projects are built Execute the project after other projects are built
  • Build periodically Regular execution
  • GitHub hook trigger for GITScm pollingFrom gihub the hookhook function to trigger the execution (which is the essence of the entire automation process, but due to my centos within the network, can not play this. Follow-up to play in the update)
  • Poll SCMTimed execution. I understand after reading the introduction

Because none of the above options are what I want, but I don't use what I want, I won't go into details.如果用的是 gitlab 还得安装 gitlab 插件这里才会有 gitlab 的选项

Build environment


The front end is only used. The node version remarks just selected are used here. If there are other environments that need to be configured, they are also configured here

Build
This is the entire plugin 精髓 2. Automatically run the script to
execute a series of command lines to complete the operation. What I configure here is to package my vue project, because the packaging path of my vue project goes directly to the corresponding directory, so I don’t have to copy the steps, which is different here. Isoha

cd /www/wwwroot/test/zbshop/vue  # 先进入到我的项目目录
node -v #检测node版本(此条命令非必要)
npm -v #检测npm版本(此条命令非必要)
npm install #安装项目中的依赖
npm run build #打包

The operation after the build is
not used, but
it is actually the same as the build, which is to execute the linux command

Click save and it's OK


Implementation process

back to the homepage

Click on the created item to go in and select Build Now. He will start to execute the pull code, and then compile the code~


In the lower left corner, there are #1 to #5, which represent the logs of each run.
Click in and

you can see the build process.


end

The installation of jekins is over here, a brief introduction to some creation projects and construction projects, but because there is no external network IP. Did not try it hookfeatures a shame, hookprinciple is git there received a new submission, it will give jekinsa signal is sent, let him get the code to automatically execute, build process code to automate the operation and maintenance, do not always own Log in to the server to pull the code

Guess you like

Origin blog.csdn.net/Jioho_chen/article/details/105820935