ABP模块签入GitLab后自动打包并推送到ProGet

发布时间 2023-05-20 13:16:40作者: 终南山人

# 1、添加一个名为下划线的解决方案文件夹

1

# 2、把解决方案根目录下的几个必要的文件添加到上述文件夹下

2

3

# 3、修改NuGet.Config,添加私有NuGet服务器的网址,并配置用户名和密码:

ABP Suite模板生成的NuGet.Config是这样的:

4

添加一行自己服务器的配置,另外有对应的节点设置用户名和密码:

4-1

#4、在解决方案根目录创建文件.gitlab-ci.yml

5

文件内容如下图所示:

8

为方便大家复制,代码块如下:

# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml

# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy
  - update-version
  - trigger-other-project

variables:
    CONFIG_VERSION_ID : 2023.51.$CI_PIPELINE_IID
    NEXUS_REPO : https://proget.abcdefg.cn/nuget/Study/
    NUGET_API_KEY : aeceb210f5irikfjskfiiiwoirwiirrie6a84817e68147
    CONFIG_NUPKG_OUTPUT_DIR : /home/gitlab-runner/nupkg/study/trade
    # Use no compression for caches
    CACHE_COMPRESSION_LEVEL: "fastest"

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  retry: 2
  tags:
    - shell
  before_script:
    - dotnet nuget locals plugins-cache --clear
  script:
    - echo "Compiling the code..."
    - cd .
    - dotnet build "src/Study.Trade.Application/Study.Trade.Application.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.Application.Contracts/Study.Trade.Application.Contracts.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.Blazor/Study.Trade.Blazor.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.Blazor.Server/Study.Trade.Blazor.Server.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.Blazor.WebAssembly/Study.Trade.Blazor.WebAssembly.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.Domain/Study.Trade.Domain.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.Domain.Shared/Study.Trade.Domain.Shared.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.EntityFrameworkCore/Study.Trade.EntityFrameworkCore.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.HttpApi/Study.Trade.HttpApi.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.HttpApi.Client/Study.Trade.HttpApi.Client.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet build "src/Study.Trade.Web/Study.Trade.Web.csproj" -c Release --force -p:Version=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Application/Study.Trade.Application.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Application.Contracts/Study.Trade.Application.Contracts.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Blazor/Study.Trade.Blazor.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Blazor.Server/Study.Trade.Blazor.Server.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Blazor.WebAssembly/Study.Trade.Blazor.WebAssembly.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Domain/Study.Trade.Domain.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Domain.Shared/Study.Trade.Domain.Shared.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.EntityFrameworkCore/Study.Trade.EntityFrameworkCore.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.HttpApi/Study.Trade.HttpApi.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.HttpApi.Client/Study.Trade.HttpApi.Client.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - dotnet pack "src/Study.Trade.Web/Study.Trade.Web.csproj" -c Release --no-build -o $CONFIG_NUPKG_OUTPUT_DIR -p:PackageVersion=$CONFIG_VERSION_ID
    - echo "推送到Nexus 3服务器..."
    - cd $CONFIG_NUPKG_OUTPUT_DIR
    - dotnet nuget push *.$CONFIG_VERSION_ID.nupkg -k $NUGET_API_KEY -s $NEXUS_REPO
    - echo "Application successfully deployed."
更新版本号:   # This job runs in the test stage.
  stage: update-version    # It only starts when the job in the build stage completes successfully.
  before_script:
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    #- ssh-keyscan $APP_SERVER > ~/.ssh/known_hosts
    #- chmod 644 ~/.ssh/known_hosts
    - cd /root/.ssh
    - cp /home/gitlab-runner/ssh/* .
  script:
    - echo "部署到Brain测试站……"
    - cd /home/gitlab-runner/scripts
    #- ssh david@$APP_SERVER
    #- docker ps
    - bash update-version.sh "Directory.Build.Study.Trade.props" "Study_Trade_Version" $CONFIG_VERSION_ID
    
触发下游:
  stage: trigger-other-project
  trigger:
    project: study/blazor-one
    branch: main

# 4、把上述文件添加到解决方案文件夹下

6

# 5、签入代码

如果GitLab里面有Runner,就会自动打包并推送到ProGet了。