How do I deploy nuget packages in Travis CI?

前端 未结 4 485
一个人的身影
一个人的身影 2021-02-08 03:14

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         


        
4条回答
  •  既然无缘
    2021-02-08 03:43

    I was trying to solve the .travis.yml problem with an aspnetcore web site. The dotnet CLI now supports commands for nuget push and executing unit testing. I also determined that the approach of having .travis.yml just call an external bash script makes things a like lot easier:

    .travis.yml

    language: csharp
    solution: ./SolutionName.sln
    mono: none
    dotnet: 3.1
    script:
    - chmod +x ./deploy.sh 
    - ./deploy.sh
    

    deploy.sh

    #!/bin/bash
    set -ev
    
    dotnet build -c $BUILD_CONFIG ./SolutionName.sln
    
    if [ $? -eq 0 ]
    then
            if [ "$BUILD_CONFIG" = "debug" ]; 
            then
                    dotnet test ./TestProject/TestProject.csproj -v normal --no-build
            else
                    echo Skip testing on non-debug build
            fi
    fi
    
    if [ $? -eq 0 ]
    then
            if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_BRANCH}" = "master" ]; 
            then
                    dotnet nuget push ./NugetProject/bin/$BUILD_CONFIG/NugetProject.*.nupkg --api-key $NUGET_API_KEY --source $NUGET_SOURCE --skip-duplicate
            else
                    echo Skip nuget for non-master build
            fi
    fi
    

    Hope this helps someone using .NET Core 2.2 and higher.

提交回复
热议问题