nuget 服务器 自动化,.Net Core 自动化部署:使用jenkins部署应用

安装docker版jenkins

因为 jenkins的 docker版本本身没有 dotnetcore的环境,所以我们需要先自己动手制作下包含 dotnet环境的 jenkins DockerContainer

Dockerfile

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

为了方便我已经把配置信息放到了github上大家可以访问直接使用

https://github.com/YahuiWong/jenkins-dotnet-core

使用步骤

初始化docker环境

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构建 dotent core的任务

构建一个自由风格的软件项目

配置源码管理资料

72d6091c8b35414b8708e5fa806b176b.jpg

配置构建脚本

如下图步骤添加打包脚本

7e297c634808485fb901f50fa544dcf0.jpg

打包脚本示例

echo'============查看打包环境================'

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# 如果针对给定运行时发布项目带上-r 如:-r centos.7-x64

cp./bin/Debug/netcoreapp2.0/您的项目路径.xml $WORKSPACE/jenkins_publish/# 拷贝swagger注释

echo'============================end build======================================='

配置发布途径

发布插件 PublishOverFTP使用说明

我这里使用的是 jenkins的 PublishOverFTP插件,安装好此插件之后在 系统管理->系统设置->Publish over FTP 里可以新增一个你要发布的ftp服务器信息。为了保证ftp可以正常连接建议尝试下右下角的 TestConfiguration确认 success

上面我们已经配置好 PublishOverFTP要用的ftp账号,新增我们新增构建后操作如下图选择此插件

1480785c295a4d72891095c7baea5c2d.jpg

然后选择配置好的ftp选项,配置如下所示

937cc1e62d634f4cb0849724e4564cd8.jpg

注意:这里的配置信息中 jenkins_publish是和打包脚本对应的

保存打包任务

立即构建

点击立即构建之后,把构建任务开始进行中

b34c1f22f2204cf0bf998b9b3dc0b3bb.jpg

如果想看的实时的构建信息可以点击如下图看到控制台输出

构建完毕

重点说明

Nuget配置说明

i/v3/index.json"/>

发布iis站点时,文件被占用

可以先用ftp插件上传一个 app_offline.htm文件,部署完站点之后删除此文件 具体参考:https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.1#app_offlinehtm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值