How to deploy nuget packages in Travis CI?

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 

Ideally, when this runs on the main branch, if it succeeds, it then deploys nuget packages as needed. The solution already has Nuget projects containing the Package.nuspec and NuGet.config for each package. I tried to force him to expand himself and did not have much success - usually I have problems with authentication, but not exclusively. I was wondering if anyone here deployed nuget packages like this one in Travis and how they did it.

+5
source share
2 answers

After much debate 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 important things to keep in mind:

  • Don't forget skip_cleanup: true - this allows you to reuse your previous build commands for your nuget package.
  • chmod +x ./deploy/deploy.sh allows chmod +x ./deploy/deploy.sh to execute a script
  • Place the API key and source as Travis environment variables. Especially for the API key, make sure they are marked so that they do not appear on the output
  • Your build may be different (not using nunit for tests, only 1 package for publishing, etc.), but the deployment process should be similar.
+7
source

The accepted answer did not help me (I do not know why). Here is what worked.

 language: csharp solution: [SolutionName].sln install: - curl -L -o nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - mono nuget.exe restore [SolutionName].sln script: - xbuild /p:Configuration=Release [SolutionName].sln - mono nuget.exe pack ./[NuspecName].nuspec - mono nuget.exe setApiKey $NUGET_API_KEY -Source $NUGET_SOURCE -Verbosity quiet - mono nuget.exe push [SolutionName].*.nupkg -Source $NUGET_SOURCE 

$NUGET_SOURCE , $NUGET_API_KEY - environment variables defined in Travis.

0
source

Source: https://habr.com/ru/post/1262429/


All Articles