1. 安装Jenkins
1.java 环境变量准备
https://blog.csdn.net/weixin_45071330/article/details/129105063
2.Jenkins的安装
2.1下载Jenkins的rpm包
目前最新版本2.346.3
安装jenkins2.346.3
通过rpm包安装Jenkins
# 通过清华大学源来安装,因为国外速度太慢。
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.346-1.1.noarch.rpm --no-check-certificate
2.2关闭防火墙selinux
[root@localhost /]# setenforce 0
[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
一定要确保字符集为 LANG="en_US.UTF-8"否则Jenkins汉化会汉化一部分;
[root@localhost /]# LANG="en_US.UTF-8"
# 通过清华大学源来安装,因为国外速度太慢。
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.346-1.1.noarch.rpm --no-check-certificate
2.3 安装Jenkins
[root@localhost ~]# yum localinstall
anaconda-ks.cfg .bash_logout .bashrc jenkins-2.346-1.1.noarch.rpm .bash_history .bash_profile .cshrc .tcshrc
[root@localhost ~]# yum localinstall jenkins-2.346-1.1.noarch.rpm -y
2.4配置Jenkins
修改用户Jenkins为root即可
[root@localhost ~]# vim /etc/sysconfig/jenkins
JENKINS_USER="root"
vim /etc/sysconfig/jenkins
修改端口,不使用8080,防止冲突。可以使用netstat -ntlp
命令查看端口占用情况。
如果是阿里云、腾讯云则不需要像上面这样配置,需要在安全组中添加允许对应端口。比如这里设置的8234。
2.5 启动Jenkins
[root@localhost /]# systemctl start jenkins
[root@localhost /]# systemctl status jenkins
2.6 启动Jenkins
地址是:http://xxx.xxx.xxx.xxx:8343
访问Jenkins。可以成功访问代表已经完成初步的部署。
解锁Jenkins:
输入命令: cat /var/lib/jenkins/secrets/initialAdminPassword
将管理员密码复制到页面输入框:xxxxxxxxxxxxxxxxxxxxx
这里jenkins会有一个比较长时间的初始化过程,耐心等待初始化完成,初始话完成的时候,浏览器会自动跳转到jenkins初次登录页面,云服务器控制台会有日志提示初次登录的密钥。
2.git
1.安装
官网下载链接如下:
https://git-scm.com/downloads/
2.Git 配置
因为Git是分布式版本控制系统,所以需要填写用户名和邮箱作为一个标识。
git config --global user.name “xxx”
git config --global user.email “xxx@qq.com”
注意:git config --global 参数,有了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然你也可以对某个仓库指定的不同的用户名和邮箱。
3.git push(推送代码至gitee/github)
# 第一步,切换到需要提交的文件的目录
cd 工作目录
# 第二步,在当前目录中生成本地的git管理
git init #会在当前目录生成一个隐藏文件夹.git
# 第三步,将需要提交的文件放入git暂存区
git add . #这个默认将该目录全部文件都添加
#也可以指定特定文件
# 第四步,给本次提交添加注释
git commit -m "first commit" #引号内容可更改
#如有报错见下文
# 第五步,连接GitHub远程仓库
git remote add origin 自己仓库的网址
# 上文提到的保存的仓库网址
# 第六步,提交
git push -u origin master
#此处master也可以是main,也可以是自定义
#详见上文Git安装第四步
至此代码成功推送到gitee