2022-11-22 13:14:34 +08:00

125 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Jenkins
date: 2022-11-09 10:30:31
author: 文永达
top_img: https://gcore.jsdelivr.net/gh/volantis-x/cdn-wallpaper/abstract/B18FCBB3-67FD-48CC-B4F3-457BA145F17A.jpeg
---
# Jenkins
```powershell
# 删除文件夹
rmdir /q /s C:\Program" "Files\nginx-1.23.2\html\dist
# 复制文件夹到指定目录
xcopy /y /e /i C:\Users\Administrator\Documents\source\XiaoDaERP-Vben\dist C:\Program" "Files\nginx-1.23.2\html\dist
# 发送文件文件夹到Linux远程服务器上
pscp -r -l root -pw Wyd210213 C:\Users\Administrator\Documents\source\XiaoDaERP-Vben\dist 8.140.174.251:/usr/local/nginx/html
```
```shell
docker run -d -p 80:80 -p 443:443 --name nginxweb --privileged=true
-v /usr/local/nginx/html/:/usr/share/nginx/html
-v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d
-v /usr/local/nginx/logs:/var/log/nginx nginx
ps aux | grep "nginx: worker process" | awk '{print $1}'
```
## 部署.Net Core 至 IIS
新建Item
![image-20221108224600422](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108224600422.png)
配置Git
![image-20221108224810869](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108224810869.png)
添加Git账户
![image-20221108224709242](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108224709242.png)
指定Jenkins从Git拉取代码目录
![image-20221108224910785](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108224910785.png)
![image-20221108224935821](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108224935821.png)
指定Jenkins定时获取Git
时间设置成H/2 * * * *
意思是每2分钟检查Git是否有变化如果有变化就会重新构建和部署
![image-20221108225020629](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108225020629.png)
构建步骤
因为Jenkins在Windows环境下所以使用 Execute Windows batch command
![image-20221108225404450](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108225404450.png)
命令:
```powershell
c:
// 切换到Git拉取代码目录
cd C:\Users\Administrator\Documents\source\XiaodaERP
// 构建.Net Core应用
dotnet build
// 停止应用程序池 saas
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:saas
// 发布.Net Core应用 需指定发布文件目录
dotnet publish -o D:\subendong\release\saas
// 启动应用程序池 saas
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:saas
```
IIS服务器应用程序池必须为无代码托管
为防止生产环境Swagger无法使用需在构建后的文件夹中编辑web.conf文件
![image-20221108230704528](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221108230704528.png)
添加如下代码
```xml
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>![1668787835347](http://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/1668787835347.png)
```
在模块中删除WebDAVModule
## Jenkins安装NodeJS环境
在Jenkins 系统管理中 插件管理 可用插件中安装`NodeJS Plugin`
并在系统管理中 全局工具配置中配置NodeJS
![image-20221122094753314](https://markdownhexo.oss-cn-hangzhou.aliyuncs.com/img/image-20221122094753314.png)
## 部署.Net Core 至 Docker容器
## Windows Server 部署Vue
### 本地Nginx
```shell
yarn
yarn build
# 删除文件夹
rmdir /q /s C:\Program" "Files\nginx-1.23.2\html\dist
# 复制文件夹到指定目录
xcopy /y /e /i C:\Users\Administrator\Documents\source\XiaoDaERP-Vben\dist C:\Program" "Files\nginx-1.23.2\html\dist
```
Linux远程服务器
```shell
# 发送文件文件夹到Linux远程服务器上
pscp -r -l root -pw Wyd210213 C:\Users\Administrator\Documents\source\XiaoDaERP-Vben\dist 8.140.174.251:/usr/local/nginx/html
```