前言
本文主要介紹了關(guān)于.Net Core自動化部署用docker版jenkins部署dotnetcore應(yīng)用的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的實現(xiàn)步驟吧。
安裝docker版jenkins
因為jenkins的docker版本本身沒有 dotnetcore的環(huán)境,所以我們需要先自己動手制作下包含dotnet環(huán)境的jenkins Docker Container
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
FROM jenkins /jenkins # Switch to root to install .NET Core SDK USER root # Show distro information! RUN uname -a && cat /etc/ *release # Based on instructiions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current # Install dependency for .NET Core 2 RUN apt-get update RUN apt-get install -y curl libunwind8 gettext apt-transport-https # Based on instructions at https://www.microsoft.com/net/download/linux-package-manager/debian9/sdk-current # Install microsoft.qpg RUN curl https: //packages .microsoft.com /keys/microsoft .asc | gpg --dearmor > microsoft.gpg RUN mv microsoft.gpg /etc/apt/trusted .gpg.d /microsoft .gpg RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list' # Install the .NET Core framework RUN apt-get update RUN apt-get install -y dotnet-sdk-2.1.4 # Switch back to the jenkins user. USER jenkins |
為了方便我已經(jīng)把配置信息放到了github上大家可以訪問直接使用
https://github.com/YahuiWong/jenkins-dotnet-core
使用步驟
初始化docker環(huán)境
1
2
3
4
|
git clone https: //github .com /YahuiWong/jenkins-dotnet-core .git cd jenkins-dotnet-core sh init.sh docker-compose up -d |
初始化配置jenkins
- Open ip:8080 on the browser
- vi jenkins_home/secrets/initialAdminPassword & Set the initialAdminPassword string to your jenkins page
至此安裝完畢。
配置jenkins構(gòu)建dotent core的任務(wù)
構(gòu)建一個自由風(fēng)格的軟件項目
配置源碼管理資料
注意:初次配置的話 需要在 添加一個可以訪問代碼地址的 Credentials
配置構(gòu)建腳本
如下圖步驟添加打包腳本
打包腳本示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
echo '============查看打包環(huán)境================' pwd ls echo $PATH whoami which dotnet dotnet --info dotnet --version echo '============================begin restore=======================================' dotnet restore echo '============================end restore=======================================' echo '============================cd project=======================================' cd ./您的項目路徑 echo '============================begin build=======================================' dotnet build # 為了生成XML注釋文件 用于swagger注釋 rm -rf $WORKSPACE /jenkins_publish mkdir $WORKSPACE /jenkins_publish dotnet publish -c:Release -o $WORKSPACE /jenkins_publish # 如果針對給定運行時發(fā)布項目帶上-r 如:-r centos.7-x64 cp . /bin/Debug/netcoreapp2 .0/您的項目路徑.xml $WORKSPACE /jenkins_publish/ # 拷貝swagger注釋 echo '============================end build=======================================' |
配置發(fā)布途徑
發(fā)布插件Publish Over FTP使用說明
我這里使用的是 jenkins的Publish Over FTP插件,安裝好此插件之后在 系統(tǒng)管理->系統(tǒng)設(shè)置->Publish over FTP 里可以新增一個你要發(fā)布的ftp服務(wù)器信息。為了保證ftp可以正常連接建議嘗試下右下角的Test Configuration確認(rèn)success
上面我們已經(jīng)配置好Publish Over FTP要用的ftp賬號,新增我們新增構(gòu)建后操作如下圖選擇此插件
然后選擇配置好的ftp選項,配置如下所示
注意:這里的配置信息中 jenkins_publish是和打包腳本對應(yīng)的
保存打包任務(wù)
立即構(gòu)建
點擊立即構(gòu)建之后,把構(gòu)建任務(wù)開始進(jìn)行中
如果想看的實時的構(gòu)建信息可以點擊如下圖看到控制臺輸出
構(gòu)建完畢
打開部署站點地址,發(fā)現(xiàn)站點已經(jīng)運行起來了
重點說明
Nuget配置說明
如果您的.NET CORE項目使用的了第三方或者自建nuget服務(wù),您需要在 配置下 jenkins_home/.nuget/NuGet/NuGet.Config的信息
如我的使用了國內(nèi)博客園的nuget加速地址和自建的nuget服務(wù)配置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<? xml version = "1.0" encoding = "utf-8" ?> < configuration > < packageSources > < add key = "nuget.org" value = "https://api.nuget.org/v3/index.json" protocolVersion = "3" /> < add key = "nuget.cnblogs.com" value = "https://nuget.cnblogs.com/v3/index.json" /> < add key = "dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" value="https://dotnet.myget.org/F/aspnetcore-dev/ap i/v3/index.json" /> < add key = "192.168.1.32:9001/nuget" value = "http://192.168.1.32:9001/nuget" /> </ packageSources > < packageRestore > < add key = "enabled" value = "True" /> < add key = "automatic" value = "True" /> </ packageRestore > < bindingRedirects > < add key = "skip" value = "False" /> </ bindingRedirects > < packageManagement > < add key = "format" value = "0" /> < add key = "disabled" value = "False" /> </ packageManagement > </ configuration > |
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對服務(wù)器之家的支持。
原文鏈接:https://www.cnblogs.com/YahuiWang/p/jenkins-docker-dotnet-core-publish.html