命名为:.gitlab-ci.yml
image: registry-vpc.cn-hangzhou.aliyuncs.com/stp/dotnet5-sonarscanner:5.0.3-1
stages:
- build
- sonar
- test
- deploy
build:
stage: build
script:
- echo $CI_JOB_ID
- echo $CI_PIPELINE_IID
- echo $CI_PIPELINE_ID
- dotnet pack -c Release --version-suffix alphb`date +%y%m%d%H%M` -o ./
artifacts:
untracked: true
expire_in: 1 days
only:
- /^dev\/.*$/
release-build:
stage: build
script:
- echo $CI_JOB_ID
- echo $CI_PIPELINE_IID
- echo $CI_PIPELINE_ID
- dotnet pack -c Release -o ./
artifacts:
untracked: true
expire_in: 1 days
only:
- master
sonar:
stage: sonar
script:
- echo $CI_COMMIT_REF_NAME
- echo $CI_PROJECT_NAME
- echo $XIAOBAO_NUGET_APIKEY
- 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'
- dotnet build
- dotnet-sonarscanner end
push_alpha:
stage: deploy
script:
- echo $XIAOBAO_NUGET_APIKEY
- dotnet nuget push '*.nupkg' -s $XIAOBAO_NUGET_SOURCE -k $XIAOBAO_NUGET_APIKEY -n true --skip-duplicate
dependencies:
- build
only:
- /^dev\/.*$/
push_release:
stage: deploy
script:
- echo $XIAOBAO_NUGET_APIKEY
- dotnet nuget push '*.nupkg' -s $XIAOBAO_NUGET_SOURCE -k $XIAOBAO_NUGET_APIKEY -n true --skip-duplicate
dependencies:
- release-build
only:
- master
test_coverage:
stage: test
before_script:
- 'echo | dotnet --version'
- export PATH="$PATH:/root/.dotnet/tools"
script:
- dotnet test --collect:"XPlat Code Coverage"
- reportgenerator "-reports:./tests/**/TestResults/*/coverage.cobertura.xml" "-targetdir:reports_coverage" -reporttypes:Html -classfilters:"+Xiaobao.*"
- reportgenerator "-reports:./tests/**/TestResults/*/coverage.cobertura.xml" "-targetdir:reports_coverage" -reporttypes:TextSummary -classfilters:"+Xiaobao.*"
- ls reports_coverage
- cat ./reports_coverage/Summary.txt
- echo 'End Summary'
coverage: /Line coverage[\s\S].+%/
artifacts:
paths:
- reports_coverage/
expire_in: 7 days
pages:
stage: deploy
dependencies:
- test_coverage
script:
- mv reports_coverage/ public/
artifacts:
paths:
- public/
expire_in: 7 days
only:
- /^dev\/.*$/
- master