Gitlab CI/CD yml 文件,用于构建、打包和部署 .net 标准 class 库作为 nuget 到 nexus 存储库
Gitlab CI/CD yml file to build, package and deploy .net standard class library as nuget to nexus repository
我有一个 .net Standard (.Net Standard 2.0)
class 库,我想将其作为 nuget package
部署到 nexus
。私有 nexus 存储库已准备就绪,我正在使用 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
图片的示例,但我们没有使用它。
提前致谢!
如果我对你的问题的理解正确,你想从你的项目中创建一个 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
我找到了一个适合我的解决方案。这是脚本,以防有人面临相同的情况 issue/requirement:
在 ci.yml
deploy
阶段:
stages:
- deploy
before_script:
- nuget restore mysolution.sln
deploy_mysolution:
stage: deploy
image:
name: crunchtime/dotnetcore-nuget-msbuild-docker
script:
- dotnet msbuild mysolution.sln /t:Clean,ReBuild /p:Configuration=Release;Platform="Any CPU"
- dotnet pack "mysolution/myproject.csproj" /p:Configuration=Release;Platform="Any CPU"
- PKGPATH=$(find myproject/bin/Release/*.nupkg)
- dotnet nuget push $PKGPATH -k $NUGET_PUSH_KEY -s https://nexus.xyz.com/repository/nuget/
only:
- master
其中 $NUGET_PUSH_KEY
是 api 键,它被保存为一个环境变量,通过运行器应用于环境。
我有一个 .net Standard (.Net Standard 2.0)
class 库,我想将其作为 nuget package
部署到 nexus
。私有 nexus 存储库已准备就绪,我正在使用 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
图片的示例,但我们没有使用它。
提前致谢!
如果我对你的问题的理解正确,你想从你的项目中创建一个 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
我找到了一个适合我的解决方案。这是脚本,以防有人面临相同的情况 issue/requirement:
在 ci.yml
deploy
阶段:
stages:
- deploy
before_script:
- nuget restore mysolution.sln
deploy_mysolution:
stage: deploy
image:
name: crunchtime/dotnetcore-nuget-msbuild-docker
script:
- dotnet msbuild mysolution.sln /t:Clean,ReBuild /p:Configuration=Release;Platform="Any CPU"
- dotnet pack "mysolution/myproject.csproj" /p:Configuration=Release;Platform="Any CPU"
- PKGPATH=$(find myproject/bin/Release/*.nupkg)
- dotnet nuget push $PKGPATH -k $NUGET_PUSH_KEY -s https://nexus.xyz.com/repository/nuget/
only:
- master
其中 $NUGET_PUSH_KEY
是 api 键,它被保存为一个环境变量,通过运行器应用于环境。