CI/CD 搭建jenkins基础测试环境构建项目(一)

 Jenkins是一个开源的持续集成工具,可以帮助开发团队自动化构建、测试和部署他们的软件项目。通过Jenkins,开发团队可以实现快速、高效地交付软件,并及时发现和解决问题,从而提高团队的生产力和软件质量。持续集成/持续交付(CI/CD)是一种自动化的软件开发实践,它的好处包括快速反馈、降低风险、提高质量、自动化流程、增强团队协作以及提高部署频率。通过CI/CD,团队可以更快地交付软件、减少错误、提高效率,并促进团队之间的合作与沟通。这种实践在现代软件开发中具有重要的作用,是提高软件交付速度和质量的关键方法之一。

jenkins Jenkins download and deployment
maven Maven – Download Apache Maven
gitlab

https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/8/gitlab-ce-16.8.2-ce.0.el8.x86_64.rpm/download.rpm

docker 阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)

安装java

[root@localhost ~]# tar zxvf jdk-17_linux-x64_bin_790090.tar.gz 
[root@localhost ~]# mv jdk-17.0.10/ /usr/local/java
[root@localhost ~]# echo 'export JAVA_HOME=/usr/local/java
> export JRE_HOME=/usr/local/java/jre
> export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib
> export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin' >> /etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version
java version "17.0.10" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)

安装maven

[root@localhost ~]# tar zxvf apache-maven-3.9.6-bin.tar.gz 
[root@localhost ~]# mv apache-maven-3.9.6 /usr/local/maven
[root@localhost ~]# vim /etc/profile
> export PATH=$PATH:/usr/local/maven/bin			#最后添加一行
[root@localhost ~]# source /etc/profile
[root@localhost ~]# mvn -v
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /usr/local/maven
Java version: 17.0.10, vendor: Oracle Corporation, runtime: /usr/local/java
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "5.14.0-162.6.1.el9_1.0.1.x86_64", arch: "amd64", family: "unix"

安装gitlab

[root@localhost ACE]# wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/8/gitlab-ce-16.8.2-ce.0.el8.x86_64.rpm/download.rpm			可以从这个网址下载
[root@localhost ~]# yum -y install curl openssh-server openssh-clients postfix cronie perl perl-devel autoconf libaio 	
安装依赖关系
启动服务,设置开机自启
[root@localhost ~]# systemctl restart postfix
[root@localhost ~]# systemctl enable postfix
[root@localhost ~]# rpm -ivh gitlab-ce-16.8.2-ce.0.el8.x86_64.rpm   安装
[root@localhost ~]# vim /etc/gitlab/gitlab.rb 			修改配置文件
将external_url 修改成本机http://IP
[root@localhost ~]# gitlab-ctl reconfigure		重新编译
[root@localhost ~]# grep "Password" /etc/gitlab/initial_root_password 			查看root密码
忘记密码找回;
[root@localhost ~]# gitlab-rails console
irb(main):001:0> user = User.where(id:1).first				指定用户
=> #<User id:1 @root>
irb(main):002:0> user.password="12345.com"				修改密码
=> "12345.com"
irb(main):003:0> user.save!								保存
=> true
配置邮箱(还是在配置文件内)
85:gitlab_rails['smtp_enable'] = true								开启smtp
gitlab_rails['smtp_address'] = "smtp.163.com"						smtp使用服务器的地址
gitlab_rails['smtp_port'] = 25										端口
gitlab_rails['smtp_user_name'] = "*************@163.com"				发送的用户名
gitlab_rails['smtp_password'] = "izacwsrelvqydeia"					授权码
gitlab_rails['smtp_domain'] = "163.com"								smtp服务域名
gitlab_rails['smtp_authentication'] = "login"						smtp授权信息
gitlab_rails['smtp_enable_starttls_auto'] = false                    邮箱安全加密关闭
gitlab_rails['smtp_tls'] = false
[root@localhost ~]# gitlab-ctl reconfigure
重新编写

[root@localhost ~]# gitlab-rails console
irb(main):001:0> Notify.test_email('*****@163.com','lalalala','asdasdasdasd').deliver_now
发送消息

备份gitlab

[root@localhost ~]# gitlab-rake gitlab:backup:create
[root@localhost ~]# ls /var/opt/gitlab/backups/     备份到该目录下
[root@localhost ~]# gitlab-ctl stop sidekiq		停止后台服务,消息队列
ok: down: sidekiq: 0s, normally up
[root@localhost ~]# gitlab-ctl stop unicorn	停止网页
[root@localhost ~]# gitlab-rake gitlab:backup:restore BACKUP=1696840271_2023_10_09_16.2.8
输入两次yes第一次是询问删除以前缓存,第二次是询问确定该此操作么。

jenkins安装

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
  sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
yum install jenkins
[root@localhost ~]# cd /usr/share/java/
[root@localhost ~]# java -jar jenkins.war --httpPort=8090
进入ip+8090端口
按照指定路径解锁jenkins
安装指定插件
创建用户,密码,开始使用jenkins

上一篇:如何本地部署Elasticsearch+cpolar实现公网查询与管理内网数据


下一篇:架构整洁之道-读书总结