jenkins download address
https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.204.2-1.1.noarch.rpm
I feel that the most difficult part of operation and maintenance is not to build and configure services, but to find various software packages.
Configure the java environment. Because jenkins is developed by java, you need to configure the java environment. Generally, the memory of java development needs to be larger.
yum install java-1.8.0-openjdk*
vi /etc/profile
AVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.272.b10-1.el7_9.x86_64
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
source /etc/profile
rpm -ivh jenkins-2.204.2-1.1.noarch.rpm
systemctl start jenkins
chkconfig jenkins on
cat /var/lib/jenkins/secrets/initialAdminPassword
#这个是查看jenkins初始密码的
You must download these plug-ins for automatic publishing
[root@jenkins ~]# ssh-keygen
[root@jenkins ~]# cat ~/.ssh/id_rsa.pub
[root@jenkins ~]# cat ~/.ssh/id_rsa
tar -xvf node-v12.18.1-linux-x64.tar.xz
vim /etc/profile
export PATH=$PATH:/root/node-v12.18.1-linux-x64/bin
source /etc/profile
[root@jenkins client-front]# npm install -g cnpm --registry=https://registry.npm.taobao.org
You need to create a public and private key on the jenkins server, send the public key to gitlab, and the private key to the jenkins plugin. Since the code I released is js, I need to install node
Click the add button after filling in
Here is to write a script. After jenkins pulls the code, it will execute the content in the script, so that the simplest jenkins automatic publishing is realized. The script should be written according to your scenario. Here I have one that I wrote. Can be used as a reference
#!/bin/bash
DATE=`date +%F`
name=${DATE}-${git_version}
#进入项目目录,将内容进行打包
get_code(){
cd /var/lib/jenkins/workspace/admin-front/ && \
/root/node-v12.18.1-linux-x64/bin/cnpm install
/root/node-v12.18.1-linux-x64/bin/cnpm run build
tar czf /opt/admin-${name}.tar.gz ./dist/*
}
#将内容通过scp拷贝只web集群组
scp_web_server(){
scp /opt/admin-${name}.tar.gz root@ip:/opt/
ssh root@ip "rm -rf /home/pro/admin/dist/*"
ssh root@ip "tar xf /opt/admin-${name}.tar.gz -C /home/pro/admin/"
}
deploy(){
get_code
scp_web_server
}
deploy
In fact, there are many plugins and usages in jenkins. Here is a brief introduction to the simplest release. Let’s talk about the problems that occurred when I released js.
After I wrote the js command in, he prompted me to be unable to use it, it should be that jenkins does not have this command and environment
Solution
Write your command path in the script, and you can execute node-related commands normally.
There may be loopholes in the article, but the most important thing is to practice it by yourself. There are a lot of articles on the Internet. Some articles may not be able to run on your own server due to environmental problems, so try more and think more.
If you have any questions, please comment