命名为:.gitlab-ci.yml

    1. image: registry-vpc.cn-hangzhou.aliyuncs.com/stp/dotnet5-sonarscanner:5.0.3-1
    2. stages:
    3. - build
    4. - sonar
    5. - test
    6. - deploy
    7. build:
    8. stage: build
    9. script:
    10. - echo $CI_JOB_ID
    11. - echo $CI_PIPELINE_IID
    12. - echo $CI_PIPELINE_ID
    13. - dotnet pack -c Release --version-suffix alphb`date +%y%m%d%H%M` -o ./
    14. artifacts:
    15. untracked: true
    16. expire_in: 1 days
    17. only:
    18. - /^dev\/.*$/
    19. release-build:
    20. stage: build
    21. script:
    22. - echo $CI_JOB_ID
    23. - echo $CI_PIPELINE_IID
    24. - echo $CI_PIPELINE_ID
    25. - dotnet pack -c Release -o ./
    26. artifacts:
    27. untracked: true
    28. expire_in: 1 days
    29. only:
    30. - master
    31. sonar:
    32. stage: sonar
    33. script:
    34. - echo $CI_COMMIT_REF_NAME
    35. - echo $CI_PROJECT_NAME
    36. - echo $XIAOBAO_NUGET_APIKEY
    37. - dotnet-sonarscanner begin /k:p$CI_PROJECT_ID /n:$CI_PROJECT_NAMESPACE\/$CI_PROJECT_NAME /v:`date +'%Y%m%d-%H:%M:%S'` /d:sonar.branch.name=$CI_COMMIT_REF_NAME /d:sonar.cs.opencover.reportsPaths='**/coverage.opencover.xml'
    38. - dotnet build
    39. - dotnet-sonarscanner end
    40. push_alpha:
    41. stage: deploy
    42. script:
    43. - echo $XIAOBAO_NUGET_APIKEY
    44. - dotnet nuget push '*.nupkg' -s $XIAOBAO_NUGET_SOURCE -k $XIAOBAO_NUGET_APIKEY -n true --skip-duplicate
    45. dependencies:
    46. - build
    47. only:
    48. - /^dev\/.*$/
    49. push_release:
    50. stage: deploy
    51. script:
    52. - echo $XIAOBAO_NUGET_APIKEY
    53. - dotnet nuget push '*.nupkg' -s $XIAOBAO_NUGET_SOURCE -k $XIAOBAO_NUGET_APIKEY -n true --skip-duplicate
    54. dependencies:
    55. - release-build
    56. only:
    57. - master
    58. test_coverage:
    59. stage: test
    60. before_script:
    61. - 'echo | dotnet --version'
    62. - export PATH="$PATH:/root/.dotnet/tools"
    63. script:
    64. - dotnet test --collect:"XPlat Code Coverage"
    65. - reportgenerator "-reports:./tests/**/TestResults/*/coverage.cobertura.xml" "-targetdir:reports_coverage" -reporttypes:Html -classfilters:"+Xiaobao.*"
    66. - reportgenerator "-reports:./tests/**/TestResults/*/coverage.cobertura.xml" "-targetdir:reports_coverage" -reporttypes:TextSummary -classfilters:"+Xiaobao.*"
    67. - ls reports_coverage
    68. - cat ./reports_coverage/Summary.txt
    69. - echo 'End Summary'
    70. coverage: /Line coverage[\s\S].+%/
    71. artifacts:
    72. paths:
    73. - reports_coverage/
    74. expire_in: 7 days
    75. pages:
    76. stage: deploy
    77. dependencies:
    78. - test_coverage
    79. script:
    80. - mv reports_coverage/ public/
    81. artifacts:
    82. paths:
    83. - public/
    84. expire_in: 7 days
    85. only:
    86. - /^dev\/.*$/
    87. - master