二、Jenkins部署你的第一个自动化流程(Vuepress项目)

一、构建你的第一个自动部署流程

因为我们的代码是存放到github上的,大致的流程就是,首先我们需要将代码从github上面拉下来,然后使用pnpm打包工具,将前端项目打包成静态文件,然后通过SSH将生成的静态文件传送到指定的服务器上,使用nginx来代理。

1.1、创建item

Jenkins拉取git代码以来jenkins中git的插件,打包遍历依赖Nodejs插件,传输文件依赖SSH插件

1.2、源文件管理

如果使用的是公开的仓库,就不用选择下面的credentials,如果是私有的仓库的话,就需要添加credential,(添加Credentials界面如下)

如果不知道如何生成github令牌,可以参考:github访问令牌token的创建方法

1.3、配置运行环境

配置NodeJS

1.4、配置执行shell

shell 复制代码
echo $WORKSPACE
node -v
npm -v
npm install -g pnpm
pnpm -v
pnpm config set registry https://registry.npmmirror.com

pnpm i
pnpm build

二、遇到的问题

2.1 配置Github的链接,代码拉不下来

这一种拉不下来是因为网络的问题,在大陆访问github,使用过的人都知道。

这里我在Jenkins服务器上面生成公钥和私钥,把公钥配置到github上面解决的。

2.2、拉取私有的Github仓库代码

当时一直没有配置对,就是没有整明白credentials这个,使用Username Password要使用github生成的令牌,因为密码github在很久之前就放弃使用了。

2.3、容器中jenkins用户没有创建目录的权限问题

当时以为拉不下来是因为jenkins没有创建目录的权限,但不是因为这个。

2.4、Github公开仓库都拉取不到

shell 复制代码
fatal: unable to access 'https://github.com/SmaxxxengC/bxxng.git/': Failed to connect to github.com port 443 after 130257 ms: Couldn't connect to server

我是用gitee的就能拉取到,还是因为在国内拉github代码的网络问题。

2.5、都配置好了,但是还是会有报错

shell 复制代码
error: RPC failed; curl 92 HTTP/2 stream 11 was not closed cleanly: CANCEL (err 8)
error: 30402 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2852)
	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2188)
	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:638)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:997)
	... 12 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

今天早上重新拉取,不知道为什么就可以拉了,应该是当时网络的问题。

2.6、将生成的文件推到指定服务器

实现:将构建后的文件推送到指定服务器上,需要哪些配置

参考:Jenkins拉取代码构建完成后部署到其他服务器(详解)

如果出现传输0个文件的问题,参考:解决SSH: Transferred 0 file(s)

相关推荐
SelectDB1 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220703 天前
如何搭建本地yum源(上)
运维
大树886 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠6 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质6 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
Inhand陈工6 天前
基于台达PLC与映翰通IG502的智慧水产养殖精准投喂与远程运维解决方案
运维·人工智能·物联网·阿里云·信息与通信
酣大智6 天前
ARP代理--工作原理
运维·网络·arp·arp代理
shushangyun_6 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
施努卡机器视觉6 天前
SNK施努卡侧滑门锁上滑轮总成自动化装配线,从零件到组件,全流程精密制造方案
运维·自动化·制造