jenkins-freestyle


jenkins的插件安装

安装好插件的jenkins 就是超人
# Jenkins存放插件的目录:
[root@jenkins ~]# ll /var/lib/jenkins/plugins/

image-20240730135817592

安装插件方法一:jenkins页面下载

image-20240730135938124

image-20240730140011435

image-20240730140051641

安装插件方法二:阿里云或者官方下载插件
https://mirrors.aliyun.com/jenkins/

# 1.下载汉化插件
[root@jenkins plugins]# wget
https://mirrors.aliyun.com/jenkins/plugins/localizationsupport/latest/localization-support.hpi
[root@jenkins plugins]# wget https://mirrors.aliyun.com/jenkins/plugins/localization-zhcn/latest/localization-zh-cn.hpi
# 2.查看文件类型
[root@jenkins plugins]# file localization-zh-cn.hpi
localization-zh-cn.hpi: Zip archive data, at least v1.0 to extract
# 3.解压插件
[root@jenkins plugins]# unzip localization-support.hpi -d localization-support
[root@jenkins plugins]# unzip localization-zh-cn.hpi -d localization-zh-cn
# 4.重启jenkins
[root@jenkins plugins]# systemctl restart jenkins
安装插件方法三-上传插件

image-20240730140542650

freestyle风格代码上线

freestyle:	自由风格
Maven:		Maven风格
Pipeline:	流水线风格

创建自由风格的项目

image-20240730140732262

01-丢弃旧的构建
就是记录保持几天 ,保持多少个该构建的项目

image-20240730140915306

02-git部分
[email protected]:root/webapp.git

添加自己的仓库位置  

注意每个用户 密钥问题    jenkins 默认的用户为jenkins 用户   # 注意!!!!!!!!
密钥对创建的是root用户的,但是Jenkins的启动用户是jenkins
## 解决方案:
### 方案一:给jenkins用户生成密钥对
# 修改jenkins用户登录bash
[root@jenkins ~]# usermod jenkins -s /bin/bash
[root@jenkins ~]# vim /etc/passwd
jenkins:x:998:996:Jenkins Automation Server:/var/lib/jenkins:/bin/bash
# 切换到jenkins用户
[root@jenkins ~]# su - jenkins
# 生成密钥对
-bash-4.2$ ssh-keygen
# 复制公钥配置到gitlab中
-bash-4.2$ cat ~/.ssh/id_rsa.pub
ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDUMyOPkFlC/lOrwOa8O1eJvo2tnus8mctDZyxF+iTTjmoUQHPf
hyOpHlC04RE1+6hdqBYuNd9ajyUWoUOmK5Cm7hxTNpPvv83m6KxJdAgzmPvFntptiRk0MDGXCnJyZDAa
bIj4awD1huIjaRbeJbVT3fCwzPOWn+a5Jjxr8ilrfo7ODRP8PgbqR3rZnQoZbld5oqlXU+61/q69aUXK
aRg5Djfq6GBuHMgO0rSyyB0lBU6UHJSpnle5w0NIs6REfrkLxBZNgcT/u0KyNQyJSCHqm8MzX1qqzE1J
sqjpq0QHVhrdk+4NvUJTXY3tMdg+p4ebw2qrTEO1ysb6djKjTYoX jenkins@jenkins
# 免密其他的web服务器
-bash-4.2$ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
-bash-4.2$ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
-bash-4.2$ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
### 方案二:修改jenkins的启动用户
# 修改配置文件
[root@jenkins ~]# vim /etc/sysconfig/jenkins
JENKINS_USER="jenkins" => JENKINS_USER="root"

image-20240730141205223

03-构建环境设置
Delete workspace before build starts :它决定了在每次构建开始之前是否要删除上一次构建的工作空间(workspace)
Use secret text(s) or file(s) : Jenkins的凭证插件允许你安全地存储和管理敏感信息。你可以在Jenkins的凭证存储中创建不同类型的凭证,如用户名和密码、SSH密钥对、秘密文本等。 在构建配置中,你可以通过变量来调用

image-20240730142101677

04-build steps (构建步揍)

image-20240730141908126

05 变量的设置
echo "BRANCH_NAME: $BRANCH_NAME"
echo "JOB_NAME: $JOB_NAME"  JOB_NAME: 仓库名
echo "WORKSPACE:$WORKSPACE" WORKSPACE: 工作目录
echo "GIT_COMMIT: $GIT_COMMIT" GIT_COMMIT :commit号