基础环境: centos7.8
下载tomcat,jenkins安装包,上传服务器
Jenkins 2.361.2+版本需要jdk11/17,jdk1.8已不再支持
到tomcat webapps目录删除所有demo文件,上传jenkins.war包到该目录
到tomcat bin目录下startup.sh启动tomcat
获取jenkins管理员密码
cat /root/.jenkins/secrets/initialAdminPassword
登录jenkins
到插件管理,修改升级站点为国内站点:https://mirrors.cloud.tencent.com/jenkins/updates/update-center.json
登录jenkins
进入jenkins管理,插件管理 安装如下插件:
maven integraion : 集成 maven 项目
gitlab 从 gitlab 拉取代码
nodejs plugin: nodejs 项目集成
publish over ssh 通过ssh发布应用
进入jenkins Global Tool Configuration, 设置 jenkins 打包环境 maven,jdk,git.nodejs;
configure system: ssh server, 设置发布服务器
新疆一个maven项目
配置工程:
配置源码:
构建工程
配置webhook
pom.xml配置如下
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.6</version><relativePath/><!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><properties><docker.repostory>192.168.191.101:80</docker.repostory><docker.registry.name>demo</docker.registry.name><docker.image.tag>1.0.0</docker.image.tag><docker.maven.plugin.version>1.4.10</docker.maven.plugin.version></properties><build><!--换成你想设置的build名称--><finalName>demo</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>com.spotify</groupId><artifactId>dockerfile-maven-plugin</artifactId><version>${docker.maven.plugin.version}</version><executions><execution><id>default</id><goals><!--如果package时不想用docker打包,就注释掉这个goal --><goal>build</goal><goal>push</goal></goals></execution></executions><configuration><contextDirectory>${project.basedir}</contextDirectory><!-- harbor 仓库用户名及密码--><useMavenSettingsForAuth>useMavenSettingsForAuth>true</useMavenSettingsForAuth><repository>${docker.repostory}/${docker.registry.name}/${project.artifactId}</repository><tag>${docker.image.tag}</tag><buildArgs><!-- 要修改成你的target目录--><JAR_FILE>${project.build.finalName}.jar</JAR_FILE></buildArgs></configuration></plugin></plugins><resources><!-- 指定 src/main/resources下所有文件及文件夹为资源文件 --><resource><directory>src/main/resources</directory><targetPath>${project.build.directory}/classes</targetPath><includes><include>**/*</include></includes><filtering>true</filtering></resource></resources></build></project>
镜像提交harbor
构建提示如下异常:
docker login 192.168.191.101 -u admin -p Harbor12345 WARNING! Using --password via the CLI is insecure. Use --password-stdin. Error response from daemon: Get "https://192.168.191.101/v2/": dial tcp 192.168.191.101:443: connect: connection refused
结局docker client默认使用https,测试环境使用http,修改docker配置文件
修改/etc/docker/daemon.json文件,添加如下
"insecure-registries" : ["http://192.168.191.101:80", "0.0.0.0"]
http要写,不然还是默认走https
依赖包安装
sudo yum install -ycurl policycoreutils-python openssh-server perl sudo systemctl enable sshd sudo systemctl start sshd sudo firewall-cmd --permanent--add-service=http sudo firewall-cmd --permanent--add-service=https sudo systemctl reload firewalld sudo yum install postfix sudo systemctl enable postfix sudo systemctl start postfix curl-fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash
配置域名及安装:
sudo EXTERNAL_URL="http://192.168.191.102" yum install -y gitlab-jh
参考命令:
重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
获取root密码cat /etc/gitlab/initial_root_password
访问gitlab.
提交代码到gitlab,通过webhook自动触发jenkins构建工程,并推送到harbor镜像仓库