当前位置: 首页 > news >正文

Jenkins 代理自动化-dotnet程序

两种方式

容器部署

本地部署

 容器部署

可自动实现,服务器重启,容器自动运行

主要将dockerfile 写好

 本地部署

1.服务器重启自动运行代理

参考下面的链接,只是把程序换成 java程序,提前确认好需要的jdk版本

Ubuntu20.04 设置开机自启_ubuntu进bos系统-CSDN博客

2.这种方式重启后,会发现,编译 dotnet 程序报错,错误如下:

/usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: The "WarnForInvalidProjectsTask" task failed unexpectedly. [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: System.InvalidOperationException: Required environment variable 'HOME' is not set. Try setting 'DOTNET_CLI_HOME' or 'HOME' and running the operation [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetValueOrThrowMissingEnvVarsDotnet(Func`1 getValue, String home, String dotnetHome) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetHome() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.<>c.<.cctor>b__20_0() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.CreateValue() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetFolderPath(SpecialFolder folder) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetFolderPath(NuGetFolderPath folder) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.PathUtility.CheckIfFileSystemIsCaseInsensitive() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.CreateValue() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.PathUtility.get_IsFileSystemCaseInsensitive() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.PathUtility.GetStringComparerBasedOnOS() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Build.Tasks.WarnForInvalidProjectsTask.Execute() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] Build FAILED. /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: The "WarnForInvalidProjectsTask" task failed unexpectedly. [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: System.InvalidOperationException: Required environment variable 'HOME' is not set. Try setting 'DOTNET_CLI_HOME' or 'HOME' and running the operation [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetValueOrThrowMissingEnvVarsDotnet(Func`1 getValue, String home, String dotnetHome) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetHome() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.<>c.<.cctor>b__20_0() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.CreateValue() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetFolderPath(SpecialFolder folder) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.NuGetEnvironment.GetFolderPath(NuGetFolderPath folder) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.PathUtility.CheckIfFileSystemIsCaseInsensitive() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at System.Lazy`1.CreateValue() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.PathUtility.get_IsFileSystemCaseInsensitive() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Common.PathUtility.GetStringComparerBasedOnOS() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at NuGet.Build.Tasks.WarnForInvalidProjectsTask.Execute() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(490,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/jenkins/agent/ /workspace/开发服1/FishServer/Server.sln] 0 Warning(s) 1 Error(s) Time Elapsed 00:00:00.75
Build step 'Execute shell' marked build as failure
Skipped archiving because build is not successful
SSH: Current build result is [FAILURE], not going to run.
Performing Post build task...
Match found for : : True
Logical operation result is TRUE

本人,进入这个代理工作目录,编译是可以的,但是不知道为什么,代理无法编译

3.ps查看代理的启动用户:

root         835  1.1  1.4 12800956 469660 ?     Sl   13:00   1:03 java -jar agent.jar -url ...

确实为root,应该不是权限的问题,查找报错日志,也未发现 Permission 或 Deny 相关内容

4.1现在只能先看最上面一条错误,看看有没有什么线索

MSB4018:

MSB4018 - MSBuild | Microsoft Learn

再加上 

Required environment variable 'HOME' is not set. Try setting 'DOTNET_CLI_HOME' or 'HOME' and running the operation

 可以确定第一条错误应该是找不到这个条件变量

4.2HOME其实就是用户的家目录

原来我手动启动 jenkins代理,使用的是 ubuntu, 所以,HOME=/home/ubuntu

5.3是否可以在 配置 开启启动时,配置 环境变量,编辑 /etc/systemd/system/rc-local.service

[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no# 在这里添加环境变量,可添加多个
Environment=HOME=/home/ubuntu[Install]
WantedBy=multi-user.target  
Alias=rc-local.service

从其服务器后,编译正常

相关文章:

  • 配置HADOOP_HOME环境变量和maven_HOME环境变量
  • 线代第二章矩阵第二课:矩阵的加法、减法、数乘
  • Python+Playwright:编写自动化测试的避坑策略
  • Mac系统升级node.js版本和npm版本并安装pnpm
  • Node.js Session 原理简单介绍 + 示例代码
  • Sui 的工具生态简化了游戏开发者的 Web3 集成流程
  • 技术与情感交织的一生 (六)
  • My Diary Pro:记录生活,珍藏回忆
  • Android NDK 编译 so 文件 抹除导出符号 反逆向
  • 如何争取高层对项目的支持
  • Docker安装 (centos)
  • GitHub 封禁中国 IP:影响、原因及应对
  • 浏览器自动化检测对抗:修改navigator.webdriver属性的底层实现
  • python的strip()函数用法; 字符串切片操作
  • 解锁动态规划的奥秘:从零到精通的创新思维解析(8)
  • 深入理解UML动态图:系统行为建模全景指南
  • CExercise_13_1排序算法_3快速排序算法,包括单向分区以及双向分区
  • Redis之缓存过期淘汰策略
  • 应急响应篇钓鱼攻击邮件与文件EML还原蠕虫分析线索定性处置封锁
  • 【Linux网络与网络编程】10.网络层协议IP
  • 游客称在网红雪山勒多曼因峰需救援被开价2.8万,康定文旅:封闭整改
  • 央行谈MLF:逐步退出政策利率属性回归流动性投放工具
  • 绿城房地产集团:近半年累计花费20.6亿元购买旗下债券
  • 家庭相册㉙在沪打拼25年,我理解了父母清晨去卖蜜饯的辛苦
  • 中国驻美国大使馆发言人就中美经贸高层会谈答记者问
  • 印观察|印巴战火与莫迪政府三重冒险:南亚火药桶已至临界点