欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JenKins使用pm2部署.net core网站

程序员文章站 2022-04-08 17:35:10
登录事先准备好的 Jenkins 1 新建任务 2 源码管理 git 输入正确地址 3 构建环境:Delete workspace before build startsAbort the build if it's stuck 打勾 4 安装事先准备好的 pm2打开shell安装参考 https: ......

登录事先准备好的 jenkins

JenKins使用pm2部署.net core网站

  • 1 新建任务

  • 2 源码管理 git 输入正确地址

  • 3 构建环境:
    delete workspace before build starts
    abort the build if it's stuck
    JenKins使用pm2部署.net core网站

    打勾

  • 4 安装事先准备好的 pm2
    打开shell安装
    参考 

sudo yum install nodejs
node -v
JenKins使用pm2部署.net core网站

npm install pm2 -g

  • 5 回到jenkins
    选择 构建=>执行shell

 JenKins使用pm2部署.net core网站

ls
cd ./vpstest.netcore/vpstest.netcore
ls

dotnet publish -c release
cd bin/release/netcoreapp2.2/publish
ls
pm2 start "dotnet vpstest.netcore.dll" --name testweb
  • 6 保存
  • JenKins使用pm2部署.net core网站
  • 选择立即构建

JenKins使用pm2部署.net core网站

  • 7 查看控制台输出

 

started by user www
building in workspace /var/lib/jenkins/workspace/dotcoretest
[ws-cleanup] deleting project workspace...
[ws-cleanup] deferred wipeout is used...
[ws-cleanup] done
no credentials specified
cloning the remote git repository
cloning repository https://github.com/www/vpstest.git
> git init /var/lib/jenkins/workspace/dotcoretest # timeout=10
fetching upstream changes from https://github.com/www/vpstest.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/www/vpstest.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url https://github.com/www/vpstest.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://github.com/www/vpstest.git # timeout=10
fetching upstream changes from https://github.com/www/vpstest.git
> git fetch --tags --progress https://github.com/www/vpstest.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
checking out revision 66cec8d481afee09a71ab9941e2ce25db6075485 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 66cec8d481afee09a71ab9941e2ce25db6075485
commit message: "修改"
> git rev-list --no-walk 66cec8d481afee09a71ab9941e2ce25db6075485 # timeout=10
[dotcoretest] $ /bin/sh -xe /tmp/jenkins8834327214949599471.sh
+ ls
dockercompsoe
license
readme.md
vpstest.netcore
+ cd ./vpstest.netcore/vpstest.netcore
+ ls
appsettings.development.json
appsettings.json
controllers
dockerfile
models
program.cs
startup.cs
views
vpstest.netcore.csproj
wwwroot
+ dotnet publish -c release
microsoft (r) build engine version 15.9.20+g88f5fadfbe for .net core
copyright (c) microsoft corporation. all rights reserved.

restoring packages for /var/lib/jenkins/workspace/dotcoretest/vpstest.netcore/vpstest.netcore/vpstest.netcore.csproj...
generating msbuild file /var/lib/jenkins/workspace/dotcoretest/vpstest.netcore/vpstest.netcore/obj/vpstest.netcore.csproj.nuget.g.props.
generating msbuild file /var/lib/jenkins/workspace/dotcoretest/vpstest.netcore/vpstest.netcore/obj/vpstest.netcore.csproj.nuget.g.targets.
restore completed in 1.81 sec for /var/lib/jenkins/workspace/dotcoretest/vpstest.netcore/vpstest.netcore/vpstest.netcore.csproj.
vpstest.netcore -> /var/lib/jenkins/workspace/dotcoretest/vpstest.netcore/vpstest.netcore/bin/release/netcoreapp2.2/vpstest.netcore.dll
vpstest.netcore -> /var/lib/jenkins/workspace/dotcoretest/vpstest.netcore/vpstest.netcore/bin/release/netcoreapp2.2/vpstest.netcore.views.dll
vpstest.netcore -> /var/lib/jenkins/workspace/dotcoretest/vpstest.netcore/vpstest.netcore/bin/release/netcoreapp2.2/publish/
+ cd bin/release/netcoreapp2.2/publish
+ ls
appsettings.development.json
appsettings.json
vpstest.netcore.deps.json
vpstest.netcore.dll
vpstest.netcore.pdb
vpstest.netcore.runtimeconfig.json
vpstest.netcore.views.dll
vpstest.netcore.views.pdb
web.config
wwwroot
+ pm2 start 'dotnet vpstest.netcore.dll' --name testweb
[pm2] starting /bin/bash in fork_mode (1 instance)
[pm2] done.
┌──────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬────────────┬──────┬──────────┐
│ app name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼────────────┼──────┼──────────┤
│ sffweb │ 0 │ n/a │ fork │ 10209 │ online │ 0 │ 33m │ 0% │ 116.3 mb │ root │ disabled │
│ testweb │ 1 │ n/a │ fork │ 13650 │ online │ 0 │ 0s │ 0% │ 3.8 mb │ root │ disabled │
└──────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴────────────┴──────┴──────────┘
use `pm2 show <id|name>` to get more details about an app
finished: success
    • 8 开放 5000 端口

      sudo firewall-cmd --add-port=5000/tcp

    • 9 打开浏览器 输入 ip:5000 成功

JenKins使用pm2部署.net core网站