jenkins安装和部署
迪丽瓦拉
2024-02-06 18:44:13
0

jenkins安装尽量不要用Docker来安装,不然会有很多坑,用我下面的方法去安装

JDK

yum install java-1.8.0-openjdk* -y

安装目录:

/usr/lib/jvm

yum  -y install epel-release
yum -y install daemonize

安装jenkins

镜像

https://mirrors.aliyun.com/jenkins/redhat-stable/?spm=a2c6h.25603864.0.0.5103166aqfIgQr

rpm -ivh jenkins-2.319.1-1.1.noarch.rpm
#修改 
vi /etc/sysconfig/jenkins
JENKINS_USER="root"
JENKINS_PORT="8888"#重启
systemctl start jenkins
systemctl enable jenkins

访问接口

http://192.168.182.130:8888/

#修改镜像源

cd /var/lib/jenkins/updatessed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json

Global Tool Configuration配置

查询java和maven环境

cat /etc/profile
末尾如下配置:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export MAVEN_HOME=/usr/share/maven
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin

根据环境配置git、maven、jdk

Configure System配置

找到 < 全局属性>

JAVA_HOME

/usr/lib/jvm/java-1.8.0-openjdk

M2_HOME

/usr/share/maven

PATH+EXTRA

$M2_HOME/bin

构建流水线项目(pipline)教程和模板

去插件中心插件安装 pipeline

使用pipeline script 构建流水

模板

pipeline {agent anystages {stage('pull code') {steps {echo 'pull code'}}stage('build project') {steps {echo 'build project'}}stage('publish code') {steps {echo 'publish code'}}}
}

第一步、打开流水线语法

使用片段生成器生成流水线脚本,

拉取代码

选择checkout: Check out from version controll =>设置git仓库地址和 Credentials=>生成流水线脚本===>
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitee-auth-password', url: 'https://gitee.com/xxxx/xxxx.git']]])===>放到steps中如下:

pipeline {agent anystages {stage('pull code') {steps {checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitee-auth-password', url: ''https://gitee.com/xxxx/xxxx.git']]])}}stage('build project') {steps {echo 'build project'}}stage('publish code') {steps {echo 'publish code'}}}
}

构建项目

同理选择 sh: Shell Script===>输入打包命令 mvn clean package -Dmaven.test.skip=true===>执行得到流水线脚本 sh ‘mvn clean package -Dmaven.test.skip=true’

pipeline {agent anystages {stage('pull code') {steps {checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitee-auth-password', url: ''https://gitee.com/xxxx/xxxx.git']]])}}stage('bulid code') {steps {echo 'bulid code'}}stage('build project') {steps {sh 'mvn clean package -Dmaven.test.skip=true'}}}
}

项目部署

doing。。。。。。。。。。。。。。。。

使用 pipeline script from SCM 方式实现流水

写好Jenkinsfile后,放到项目的根目录下,注意是J是大写的,然后推送到远程仓库
然后流水线使用 pipeline script from SCM,弃用UI界面的pipeline script 流水方式

相关内容