Linux下使用Jenkins自动化构建Dotnet Core项目并以systemd服务形式发布

环境准备

  • 系统
    linux
  • 环境
    dotnet core

jenkins:自动化部署
.NET Core 2.2 SDK:用来编译项目
.NET Core 2.2 Runtime:The runtime includes everything you need to run .NET Core applications. The runtime is also included in the SDK
项目以linux服务的方式使用Kestrel发布,再配上nginx,可以反向代理的方式访问项目
jenkins相关配置:


源码管理配置

构建触发器

execute shell

有shell命令可以看出,再次以systemd服务形式发布的ASP.NET Core项目

在/lib/systemd/system下添加 mcl.service
vim /lib/systemd/system/mcl.service

image.png

wq!保存退出
运行服务检查服务是否能运行
sudo systemctl start mcl.service
sudo systemctl status mcl.service

fcj@ubuntu:~$ sudo  systemctl status mcl.service
● mcl.service - run MclServer on ubuntu
   Loaded: loaded (/lib/systemd/system/mcl.service; disabled; vendor preset: ena
   Active: active (running) since Sat 2019-08-31 05:08:22 CST; 1h 16min ago
 Main PID: 5640 (dotnet)
    Tasks: 17 (limit: 3492)
   CGroup: /system.slice/mcl.service
           └─5640 /usr/bin/dotnet /var/lib/jenkins/workspace/MclServerCore/Integ

8月 31 05:08:22 ubuntu systemd[1]: Started run MclServer on ubuntu.
8月 31 05:08:24 ubuntu dotnet[5640]: Hosting environment: Production
8月 31 05:08:24 ubuntu dotnet[5640]: Content root path: /var/lib/jenkins/workspa
8月 31 05:08:24 ubuntu dotnet[5640]: Now listening on: http://[::]:8020
8月 31 05:08:24 ubuntu dotnet[5640]: Application started. Press Ctrl+C to shut d

服务正常后,关闭服务sudo systemctl stop mcl.service,保存jenkins的配置,构建项目:
控制提输出报错

+ sudo systemctl stop mcl.service
sudo: 没有终端存在,且未指定 askpass 程序
Build step 'Execute shell' marked build as failure
Finished: FAILURE

可见jenkins的shell脚本操作systemd服务出错了

fcj@server:~$ sudo visudo
对sudo 设置成免密形式

image.png

再次执行jenkins构建:


image.png

在浏览器访问项目发布的页面:


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容