1、在服务器上安装dotnet SDK
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install libunwind libicu
sudo yum install dotnet-sdk-3.1
2、查看配置
管理员登陆gitlab,在菜单overvire-runner中的右侧区域找到你的ip和token,后面注册会用到。
3、安装配置Gitlab-Runner
3.1 下载最新版
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
3.2 安装
sudo yum install gitlab-runner
3.3 注册
注册说几个关键点,首先输入命令
sudo gitlab-runner register
这里复制粘贴步骤2的ip地址
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
这里复制粘贴步骤2的token
Please enter the gitlab-ci token for this runner
xxx
这里输入runner执行者,输入shell
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell
4、配置
还是步骤2的界面,注册完后,在下方列表会出现已注册的runner,点击token标题进入配置。
勾选这里,表示每次提交不管有没有tag都会执行runner任务。
下方需要启动runner的git项目,后面点击启用。
5、asp.net core 项目配置
5.1 在项目根目录中添加 .gitlab-ci.yml 文件。
variables:
GIT_STRATEGY: none
stages:
- test
test_job:
stage: test
only:
- master
script:
- cd /home/gitproject
- rm -rf /home/gitproject/gitrunner
- git clone http://root:12345678@192.168.161.140/Team/gitrunner.git
- cd ./gitrunner
- dotnet restore
- rm -rf /home/project/gitrunner
- if [ "$(docker ps | grep gitci)" ]; then
- docker stop gitci
- docker rm gitci
- fi
- if [ "$(docker images | grep gitciimages)" ]; then
- docker rmi gitciimages
- fi
- dotnet publish -c Release --output /home/project/gitrunner
- cd /home/project/gitrunner
- docker build -t gitciimages .
- docker run -d -v /home/project/gitrunner:/code -p 5001:80 --name gitci --restart always gitciimages
5.2 在启动项目里面加 Dockerfile文件
COPY . /code
WORKDIR /code
ENV ASPNETCORE_URLS http://+:5000
EXPOSE 5000
CMD ["dotnet","project.dll"]
【参考文章】