首页 > 解决方案 > Gitlab CI/CD yml 文件,用于构建、打包和部署 .net 标准类库作为 nuget 到 nexus 存储库

问题描述

我有一个.net Standard (.Net Standard 2.0)类库,我想将其部署nexusnuget package. 私有关系存储库已准备就绪,我正在使用它Gitlab进行代码管理。

在 Gitlab 中,我添加了 gitlab-ci.yml 文件,该文件将触发构建和部署,但仍然没有足够的步骤:

stages:
  - build
  - package
  - deploy

build_image:
  stage: build  
  only:
    - master
  script:
    - echo "Restoring NuGet Packages…"
    - RUN dotnet restore
    - echo "Building solution…"
    - RUN dotnet build --no-restore -c Release -o

package_dev:
  stage: package
  script:
    - 

deploy_dev:
  stage: deploy
  environment:
    name: development
  only:
    - master
  script:
    - 

我的问题是如何配置此文件以触发构建然后执行packaging and deploy/push to nexus repo

我不知道我是否描述得很好,因为我对这个话题完全陌生。我发现了一些使用MAVEN图像的例子,但我们没有使用它。

提前致谢!

标签: nugetgitlabnexusgitlab-ci.net-standard

解决方案


如果我正确理解您的问题,您想从您的项目中创建一个 nuget 包并将其上传到 Nexus Repo。你可以一步到位。

build-and-upload:
  image: <dot-net image>
  stage: build-and-upload
  environment:
    name: dev/test/prod
  only:
    - master
  before_script:
    - aws commands if you need to assume a deploy role.
  script:
    - ./scripts/nuget_publish.sh




And this is how your nuget_publish.sh will look like

dotnet build
dotnet pack
NEXUS_SOURCE=<Nexus_Source_Repo_Url>
NEXUS_API_KEY=<Nexus_Source_Repo_Api_Key>
dotnet nuget push <ProjectName>/bin/Debug/*.nupkg --source $NEXUS_SOURCE --api-key $NEXUS_API_KEY


推荐阅读