Hello,
I’m looking for a way to make an autodeploy of NuGet packages after the compilation. So far I’ve successfully set the CI/CD on TravisCI but I want to publish the NuGet package only from the master
branch and not from the pull request
branch.
This is what the travis.yml
should look like to make the CI/CD with the deploy.
language:
csharp
sudo: required
mono: none
dotnet: 3.0
os:
- linux
global:
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
- DOTNET_CLI_TELEMETRY_OPTOUT=true
before_script:
- dotnet restore solution.csproj
- dotnet restore solutionTest.csproj
script:
- dotnet build solution.csproj --configuration Release
- dotnet test solutionTest.csproj --configuration Release
after_script:
- dotnet pack solution.csproj --configuration Release
- dotnet nuget push bin\Release\*.nupkg -s "some-source"
As you can see the process is pretty simple
- Restore the solution
- Build the solution
- Test the solution
- Generate the NuGet package
- Push the package to the source
What do I want
I want this to only happen in the master
branch after the pull request
is completed.
What happens now
When I do a PR to the master branch, in order to be able to be merged it needs to build, so the TravisCI builds everything which builds, test, packs the solution, and also includes the package publication, that is what I don’t want.
Remarks
Can I set the scripts to be run only in a specific branch? Something like the following:
[ommited code travis.yml]
branch:
master:
after_script:
- dotnet pack solution.csproj --configuration Release
- dotnet nuget push bin\Release\*.nupkg -s "some-source"
Hopefully this is understandable, I have created a question on Stackoverflow, just in case if you also want to answer there.