Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

注意:

也许是这么用,没有深入研究。

另外使用了podman代替docker。

第一步:将代码上传到码云(git其他的也可以)

我用了原来的dotnet示例代码。

创建了一个mvc示例项目,一个单元测试项目

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 第二步,将代码上传到马云

第三步配置Jenkins

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

我选择了FreeStyle Project

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 这里将git的地址复制进来

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 检查提交后自动进行构建

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 这里我使用的是powershell脚本

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 构建后有许多可以操作的选项

测试发布一个构建

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 

效果:

检测到有提交

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 好了

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

 

 下面是构建日志

Started by an SCM change
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/JenkinsDotnetTest
The recommended git tool is: NONE
No credentials specified
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://gitee.com/xxxx/jenkins-dotnet-test.git # timeout=10
Fetching upstream changes from https://gitee.com/xxxx/jenkins-dotnet-test.git
> git --version # timeout=10
> git --version # ‘git version 2.18.4‘
> git fetch --tags --progress -- https://gitee.com/xxxx/jenkins-dotnet-test.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 44d5c510f4e08b593ef28e054a0c501d9e75f9e6 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 44d5c510f4e08b593ef28e054a0c501d9e75f9e6 # timeout=10
Commit message: "单元测试"
First time build. Skipping changelog.
[JenkinsDotnetTest] $ pwsh -NonInteractive -File /tmp/jenkins8561056685409721394.ps1
单元测试
Test run for /var/lib/jenkins/workspace/JenkinsDotnetTest/test/JenkinsMsTest/bin/Debug/netcoreapp3.1/JenkinsMsTest.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0-dev+55e7e45431c9c05656c999b902686e7402664573
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

Test Run Successful.
Total tests: 1
Passed: 1
Total time: 2.0783 Seconds
[JenkinsDotnetTest] $ pwsh -NonInteractive -File /tmp/jenkins3424907451063664942.ps1
启动自动构建
生成docker镜像
STEP 1: FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
STEP 2: WORKDIR /app
--> Using cache c6361ead7d41eedec2ca44527a6d6535ad3b6dba06024f9c7e54967762d503b0
STEP 3: EXPOSE 80
--> Using cache e6040c59539d36ec82a0790d7f0c4b3efd458d32afe2e2ad4fd9ab79d2422a50
STEP 4: EXPOSE 443
--> Using cache 68d023851917676fcf9d49baa7fbc2d640f45736ab62d1c5de531f63501f482c
STEP 5: FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
STEP 6: WORKDIR /src
--> Using cache a56e1410c0613f5da417a1be839872a4746e791c8e73d348aa21e17b3b45bfac
STEP 7: COPY ["src/JenkinsTest.csproj", "src/"]
--> Using cache f802faf8209514024e2f38ce9516b0078629e5db537f6d6e3f74c681b5b9d249
STEP 8: RUN dotnet restore "src/JenkinsTest.csproj"
--> Using cache dd8fef4ceb6157cab235b5baf11f0449e23fa977b00dbfc1b4ac2f464e2f3c60
STEP 9: COPY . .
ef4723773175e1c467f9dcc290e6fbd47b45ecd9323a6e00ebd46f3e8ecbadcf
STEP 10: WORKDIR "/src/src"
1b11759c7c580e7ba51c15d01856c63b0d0618a7b3a14c48fb773dfaf3cd069f
STEP 11: RUN dotnet build "JenkinsTest.csproj" -c Release -o /app/build
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore...
All projects are up-to-date for restore.
JenkinsTest -> /app/build/JenkinsTest.dll
JenkinsTest -> /app/build/JenkinsTest.Views.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:14.16
e4fd37da9353664babafab4d3d0e8c83e78f2f18cdda0c0e41230f32278171a2
STEP 12: FROM e4fd37da9353664babafab4d3d0e8c83e78f2f18cdda0c0e41230f32278171a2 AS publish
STEP 13: RUN dotnet publish "JenkinsTest.csproj" -c Release -o /app/publish
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore...
All projects are up-to-date for restore.
JenkinsTest -> /src/src/bin/Release/netcoreapp3.1/JenkinsTest.dll
JenkinsTest -> /src/src/bin/Release/netcoreapp3.1/JenkinsTest.Views.dll
JenkinsTest -> /app/publish/
a4e523cccc824e11510abd4685b48ee889f2b00f75e3e8ea8952761bfbd7dc49
STEP 14: FROM 68d023851917676fcf9d49baa7fbc2d640f45736ab62d1c5de531f63501f482c AS final
STEP 15: WORKDIR /app
--> Using cache 852684f3090eaef3ef3f05e4783e021e84ecda419af2b004b3960b1a54b5e211
STEP 16: COPY --from=publish /app/publish .
7f62a9f0711bb292f7faf2777a33654df3a3689892c3b96b0a21e6ab4257d1e6
STEP 17: ENTRYPOINT ["dotnet", "JenkinsTest.dll"]
STEP 18: COMMIT aspnetcoretest:v1
259c7a26ee4525742ab7105f9db18ea28e052ee195bc2cd79f7cb4deabb3d6e7
[JenkinsDotnetTest] $ pwsh -NonInteractive -File /tmp/jenkins630220471738520011.ps1
部署镜像
adb4a8e220452224f5a95b5d0f6067e780c37e5a4ec60654fe9141871ac4596e
--2020-09-20 22:31:51-- http://localhost:8088/
正在解析主机 localhost (localhost)... ::1, 127.0.0.1
正在连接 localhost (localhost)|::1|:8088... 失败:Connection refused。
正在连接 localhost (localhost)|127.0.0.1|:8088... 已连接。
已发出 HTTP 请求,正在等待回应... 读取文件头错误 (Connection reset by peer)。
重试中。

--2020-09-20 22:31:52-- (尝试次数: 2) http://localhost:8088/
正在连接 localhost (localhost)|127.0.0.1|:8088... 已连接。
已发出 HTTP 请求,正在等待回应... 读取文件头错误 (Connection reset by peer)。
重试中。

--2020-09-20 22:31:54-- (尝试次数: 3) http://localhost:8088/
正在连接 localhost (localhost)|127.0.0.1|:8088... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [text/html]
正在保存至: “index.html.1”

0K .. 269M=0s

2020-09-20 22:31:54 (269 MB/s) - “index.html.1” 已保存 [2174]

[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] done
Finished: SUCCESS

上面测试链接的时候,有几处错误,应该是我电脑在转码,速度比较慢,所以失败了,但是尝试第三次也成功了。

一下篇再搭建一个虚拟机,当作发布服务器。

Centos8 Jenkins asp.net.core CICD 简单记录下dotnet cicd(二)

上一篇:02 JSON基础知识


下一篇:https