内容较多,主要分为以下4方面内容:

  • Jenkins的安装部署(centos 7+)
  • .net在linux平台CI流程所需的插件管理&配置
  • Jenkins配置连接Gitlab(也可使用对应插件连接SVN,TFS作为源码仓库)
  • 基于Jenkins的CI流程构建

Jenkins安装部署

  • 下载[Jenkins最新版];
  • 在服务器上jenkins.war所在目录建立脚本:start-jenkins.sh:
#!/bin/bash
JENKINS_ROOT=/opt/jenkins
export JENKINS_HOME=$JENKINS_ROOT/jenkins_home
nohup java -jar $JENKINS_ROOT/jenkins.war --httpPort= > jenkins.log >& &
  • 修改脚本执行权限:
chmod a+x start-jenkins.sh
  • 执行脚本:
/bin/bash start-jenkins.sh
  • 访问服务器地址(测试服务器地址,脚本指定端口):
http://10.200.XX.XX:8000

.net在linux平台CI流程所需的插件管理&配置

Jenkins在当前开发环境下所需要的插件列表如下:

  • Docker相关插件
  1. CloudBees Docker Build and Publish plugin (This plugin provides the ability to build projects with a Dockerfile, and publish the resultant tagged image (repo) to the docker registry.)
  2. Docker plugin (This plugin allows slaves to be dynamically provisioned using Docker.)
  3. docker-build-step (This plugin allows to add various Docker commands into you job as a build step.)
  • CaaS插件
  1. Kubernates plugin (This plugin allows slaves to be dynamically provisioned on multiple Docker hosts using Kubernetes.)
  • Building插件
  1. Git plugin
  2. Nuget plugin
  3. MSBuild
  • Gitlab Connector
  1. Gitlab Hook Plugin
  2. GitLab Plugin

Jenkins配置连接Gitlab

  • 在jenkins服务器上新生成SSH key
  1. 通过以下指令检查服务器是否已经存在SSH Key:
    1. cat ~/.ssh/id_rsa.pub
  2. 如果没有Key,则通过以下指令新生成一个Key:
    1. ssh-keygen -t rsa -C "jiakai@gridsum.com"
  3. 通过刚才的指令: cat ~/.ssh/id_rsa.pub 获得生成的Key(公钥部分)
  • 在生成Key对应的账户个人"Profile Settings"下的"SSH Keys"标签下,新增这个Key, 新增的Title直接设置为账户名即可
  • 完成后在"Your SSH Keys"下可以看到新增的SSH Key公钥信息

基于Jenkins的CI流程构建


Jenkins内部的各流程说明如下:

  • 测试项目目录结构如下图:

  • Source Copy

    • 该过程对应Jenkins工作项中的"源码管理"工作区,在该工作区中选中"Git",配置Repository URL及上一步已经添加好的Credential即可,并制定需要编译的分支,比如"master"分支;
    • 该流程配置完毕后,可保存工作项,然后"立即构建",正确的话将在Jenkins工作区目录的~/workspace/${JobName}/路径下,查看到从制定的Git Repository上拉取的源码;
  • Nuget还原包
    • Nuget还原包依赖nuget.exe(需要mono),下载nuget.exe(这里我下载的是2.8.6版本),拷贝至Jenkins服务器的Jenkins运行目录下的.nuget文件夹;
    • 在Nuget还原工作项的"Execute shell"中,使用nuget.exe还原包即可:
      mono ../../.nuget/nuget.exe restore ${solution file path(.sln)}
    • 注:nuget2.5版本缺少必要的操作(restore),不可用。
    • 在执行过程可能报以下错误:
      WARNING: Error: TrustFailure (The authentication or decryption has failed.)
      WARNING: Error: TrustFailure (The authentication or decryption has failed.)
      WARNING: Error: TrustFailure (The authentication or decryption has failed.)
      WARNING: Error: TrustFailure (The authentication or decryption has failed.)
      WARNING: Error: TrustFailure (The authentication or decryption has failed.)

      需要引入秘钥证书至machine store(注意不要引入到user store):

      mozroots --import --machine --sync
      certmgr -ssl -m https://go.microsoft.com
      certmgr -ssl -m https://nugetgallery.blob.core.windows.net
      certmgr -ssl -m https://nuget.org
  • mono编译包
    • 安装mono后(以安装路径/usr/mono为例),重启 jenkins,查看jenkins系统设置中的环境变量,其中的PATH变量,并确保mono的bin目录已经在PATH环境变量之中:
    • 然后直接调用xbuild编译项目:

      xbuild TestApi.sln
  • [可选步骤]将编译后的文件形成发布文件,例如:
    # Get the deploy files Ready
    if [ ! -x ./deploy ] ;then
    mkdir deploy
    else
    rm ./deploy/* -rf
    fi
    cp ./src/DemoApi/bin ./deploy/bin -Rf
    cp ./src/DemoApi/packages.config ./deploy/packages.config -f
    cp ./src/DemoApi/Web.config ./deploy/Web.config -f
    cp ./src/DemoApi/Global.asax ./deploy/Global.asax -f
  • 构建Docker镜像所需的Dockerfile
    • 由于我们这里需要在jexus中部署我们的demo api,因此采用公司docker源中的jexus服务器V3版镜像:

      if [ -f ./Dockerfile ] ;then
      rm ./Dockerfile -f
      fi
      cat > ./Dockerfile <<EOF
      FROM .xxx.xxx.xxx:/library/mono-jexus:v3
      COPY ./deploy /data
      CMD /usr/jexus/jws start && /usr/sbin/sshd -D
      EOF
  • 打包Docker镜像并推送至公司的Docker源
    • 这里我们用到CloudBees Docker Build and Publish plugin这个插件
    • 按照如下图所示的配置
    • 在“高级设置”中,勾选"Skip tag as latest","Force Pull",并且,如果Dockerfile不在默认(./)目录,还需要在“Dockerfile Path”中指定Dockerfile的具体位置:
  • 删除过期的Docker镜像

    在成功生成新版本的镜像之后,需要删除(或untag)之前版本的镜像:

#Untag the expired images except the newest image id
#Init the parameters
IMG_NAME=demoapi
IMG_URL=/gridsum/ld/demoapi
(docker images | grep ${IMG_NAME} | awk '{print $2}') >.version
#Delete expired images
count=
maxnum=$(wc -l .version | awk '{print $1}')
 ] ;then
sort .version | while read line
do
if [ $count -lt $maxnum ] ;then
    docker rmi $IMG_URL:$line
    let count=count+
fi
done
fi
#Clean the parameters
unset IMG_NAME
unset IMG_URL
rm .version -f
  • 建立项目对应的RC文件,注意在RC中指定的Docker镜像版本为本次build的镜像版本:

  • 启动新的容器:
# Delete the existed rc by kubectl
#NEED to redrect stderr into null or the BUILD process will be FAILED if there IS a RC running
/opt/jenkins/kube/kubectl -s http://10.200.xx.xx:8080 delete rc demoapi 2>/dev/null
#Create the k8s rc by kubectl
/opt/jenkins/kube/kubectl -s http://10.200.xx.xx:8080 create -f ./rc.yaml
  • 容器对应的服务最好手动建立,因为服务是常态化的,一般不随源代码版本更迭发生变化,因此服务的创建可以实现创建好;
  • 最后对已发布的服务进行简单的功能测试,通过curl即可:

.net项目在linux平台的CI流程(基于Jenkins+mono+jexus)的更多相关文章

  1. 转:sock_ev——linux平台socket事件框架(基于数据报的测试程序) .

    上一篇已经做过注释,这一篇直接上代码 /******************************************************************************** ...

  2. 转:sock_ev——linux平台socket事件框架(基于字节流的测试程序) .

    原文:http://blog.csdn.net/gdutliuyun827/article/details/8257186 由于工作与学习的需要,写了一个socket的事件处理框架,在公司写的已经使用 ...

  3. 转载~Linux 平台下阅读源码的工具

    Linux 平台下阅读源码的工具 前言 看源代码是一个程序员必须经历的事情,也是可以提升能力的一个捷径.个人认为: 要完全掌握一个软件的方法只有阅读源码在Windows下有sourceinsight这 ...

  4. CentOS安装gitlab,gerrit,jenkins并配置ci流程

    CentOS安装gitlab,gerrit,jenkins并配置ci流程 By Wenbin juandx@163.com 2016/4/9 这是我参考了网上很多的文档,配置了这三个软件在一个机器上, ...

  5. 基于Linux平台的libpcap源码分析和优化

    目录 1..... libpcap简介... 1 2..... libpcap捕包过程... 2 2.1        数据包基本捕包流程... 2 2.2        libpcap捕包过程... ...

  6. Linux平台延时之sleep、usleep、nanosleep、select比较

    Linux平台延时之sleep.usleep.nanosleep.select比较 标签: 嵌入式thread线程cpu多线程 2015-05-05 15:28 369人阅读 评论(0) 收藏 举报 ...

  7. VS2010下创建的VB.NET项目打包发布安装包的流程

    VS2010下创建的VB.NET项目打包发布安装包的流程 参考:http://blog.csdn.net/liuyanlinglanq/article/details/8609675  关于relea ...

  8. 服务端技术进阶(一)web项目的部署(发布)流程

    web项目的部署(发布)流程 在myeclipse下新建web工程abc.系统设置默认如下: 项目保存位置:workspace目录\abc.Source文件夹:src,保存所有的java类文件(.ja ...

  9. Linux平台安装MongoDB及使用Docker安装MongoDB

    一.Linux平台安装MongoDB MongoDB 提供了 linux 各发行版本 64 位的安装包,你可以在官网下载安装包. 下载地址:https://www.mongodb.com/downlo ...

随机推荐

  1. Android AsyncTask 深度理解、简单封装、任务队列分析、自定义线程池

    前言:由于最近在做SDK的功能,需要设计线程池.看了很多资料不知道从何开始着手,突然发现了AsyncTask有对线程池的封装,so,就拿它开刀,本文将从AsyncTask的基本用法,到简单的封装,再到 ...

  2. android adb pull push

    adb命令下pull的作用是从手机端向电脑端拷文件. adb pull /storage/emulated/0/Download/**.apk  /Users/edwin/Downloads adb命 ...

  3. Android编码规范01

    目标: 掌握Java & Android命名规范 在研究Android源代码的基础上改进命名规范 考核内容 说出四种常用的命名法 比较java和C#的命名规范的不同点 总结: 读不同程序员写的 ...

  4. 敏捷开发与jira之项目现状

    从三个方面概述项目的现状 资源组织结构 资源中的特殊角色 •反馈问题接口人 –测试兼,处理实施反馈回来的问题,Bug复现后分配给开发负责人:需求指向需求做进一步的需求分析 •流程反馈处理人 –测试或开 ...

  5. IT人创业之融资方式 - 创业与投资系列文章

    对于想要创业的IT人,最基本的就是需要资金和团队.笔者在经历了自己制定的职业道路之后(见文:IT从业者的职业道路(从程序员到部门经理) - 项目管理系列文章),进行过投资(见文:IT人经济思维之投资 ...

  6. SSRS Reports 2008性能优化案例

    我们的一个Reporting Service服务上部署了比较多的SSRS报表,其中有一个系统的SSRS报表部署后,执行时间相对较长,加之供应商又在ASP.NET页面里面嵌套了Reporting Ser ...

  7. C# random helper class

      项目中经常需要模拟些假数据,来做测试.这个随机生成数据的helper类就应用而生: using System; using System.Text; using System.Windows.Me ...

  8. web项目log4j的配置模板

    log4j.properties文件: log4j.rootLogger=DEBUG,Console,File   //测试环境 为 debug, 生产时勿必改为info log4j.appender ...

  9. 支持+-*/()int 型数据的计算机c++实现

    #include <iostream> #include<sstream> using namespace std; template<typename T> cl ...

  10. 【2016-11-3】【坚持学习】【Day18】【我认识的ORM】

    我学过或者用过的ORM有几种 EF NHibernate DevExpress  xpo (第一家公司用这个,也是很省力的orm,现在已经不记得了.) 今天晚上想找一下有没有轻量级的orm: flue ...