如何在Travis CI中部署nuget软件包? [英] How do I deploy nuget packages in Travis CI?

查看:62
本文介绍了如何在Travis CI中部署nuget软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行Travis CI的nuget软件包.这是我的yml:

I have a nuget package that runs Travis CI for its builds. Here is my yml:

language: csharp
solution: TreasureGen.sln
install:
  - nuget restore TreasureGen.sln
  - nuget install NUnit.Runners -OutputDirectory testrunner
script:
  - xbuild TreasureGen.sln /p:TargetFrameworkVersion="v4.5" /p:Configuration=Stress
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Unit/bin/Stress/TreasureGen.Tests.Unit.dll
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.IoC/bin/Stress/TreasureGen.Tests.Integration.IoC.dll
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Tables/bin/Stress/TreasureGen.Tests.Integration.Tables.dll
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Stress/bin/Stress/TreasureGen.Tests.Integration.Stress.dll

理想情况下,当它在master分支上运行时,如果成功,则将根据需要部署nuget软件包.解决方案中已经有Nuget项目,每个项目包含 Package.nuspec NuGet.config 文件.我曾尝试让它自己部署,但并没有取得太大的成功-通常我会遇到身份验证方面的问题,但不是排他性的.我想知道这里是否有人在Travis中部署了像这样的nuget包,以及他们是如何做到的.

Ideally, when this runs on the master branch, if it is successful, it would then deploy the nuget packages as needed. There are already Nuget projects in the solution, which contain Package.nuspec and NuGet.config files for each package. I have tried getting it to deploy myself and have not had much success - typically I run into problems with the authentication, but not exclusively. I was wondering if anyone here has deployed nuget packages like this in Travis and how they did it.

推荐答案

经过反复的摸索和试验,我终于找到了解决方法.

After much fiddling and experimentation, I finally found a solution.

.travis.yml

language: csharp
solution: TreasureGen.sln
install:
  - nuget restore TreasureGen.sln
  - nuget install NUnit.Runners -OutputDirectory testrunner
script:
  - xbuild TreasureGen.sln /p:TargetFrameworkVersion="v4.5" /p:Configuration=Stress
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Unit/bin/Stress/TreasureGen.Tests.Unit.dll
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.IoC/bin/Stress/TreasureGen.Tests.Integration.IoC.dll
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Tables/bin/Stress/TreasureGen.Tests.Integration.Tables.dll
  - mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Stress/bin/Stress/TreasureGen.Tests.Integration.Stress.dll
deploy:
  skip_cleanup: true
  provider: script
  script: chmod +x ./deploy/deploy.sh && ./deploy/deploy.sh $NUGET_API_KEY $NUGET_SOURCE
  on:
    branch: master

deploy.sh

ApiKey=$1
Source=$2

nuget pack ./TreasureGen/TreasureGen.nuspec -Verbosity detailed
nuget pack ./TreasureGen.Domain/TreasureGen.Domain.nuspec -Verbosity detailed

nuget push ./DnDGen.TreasureGen.*.nupkg -Verbosity detailed -ApiKey $ApiKey -Source $Source
nuget push ./DnDGen.TreasureGen.Domain.*.nupkg -Verbosity detailed -ApiKey $ApiKey -Source $Source

以下是要记住的一些关键事项:

Here are some of the key things to remember:

  1. 不要忘记 skip_cleanup:true -这使您可以重复使用您以前的nuget软件包的构建命令结果
  2. chmod + x ./deploy/deploy.sh 允许脚本可执行
  3. 将您的API密钥和源放置为Travis环境变量.特别是对于API密钥,请确保将其标记为不显示在输出中
  4. 您的构建可能会有所不同(不使用nunit进行测试,仅发布1个软件包,等等),但是部署过程应该相似.
  1. Do not forget the skip_cleanup: true - this allows you to reuse your previous build command results for your nuget package
  2. The chmod +x ./deploy/deploy.sh allows for the script to be executable
  3. Place your API Key and Source as Travis environment variables. Especially for the API Key, make sure they are marked to not show in the output
  4. Your build may differ (not using nunit for tests, only 1 package to publish, etc.), but the deployment process should be similar.

这篇关于如何在Travis CI中部署nuget软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆