安装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的任务
构建一个自由风格的软件项目
配置源码管理资料
配置构建脚本
如下图步骤添加打包脚本
打包脚本示例
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账号,新增我们新增构建后操作如下图选择此插件
然后选择配置好的ftp选项,配置如下所示
注意:这里的配置信息中 jenkins_publish是和打包脚本对应的
保存打包任务
立即构建
点击立即构建之后,把构建任务开始进行中
如果想看的实时的构建信息可以点击如下图看到控制台输出
构建完毕
重点说明
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