This image is used to build ASP.NET projects, and contains the jq and Sonar Scanner for MSBuild.
1.8K
This image is used to build ASP.NET projects, and contains the jq library to allow PR features in bitbucket pipelines, plus the neccesary dependencies to run Sonar Scanner for MSBuild.
Build:
docker build -t sonar-build .
Interact:
docker run -it --rm sonar-build bash
This image is meant for use as part of a CI build pipeline. Here is an example on how to use the image with Bitbucket Pipeline:
# This is a sample build configuration for .NET Core.
# Only use spaces to indent your .yml configuration.
# -----
pipelines:
default:
master:
- step:
name: Build and test C# and javascript/typescript project
image: itminds/aspnetcore-sonar-build
caches:
- node
- dotnetcore
script:
# Install and test js/ts. This script can be replaced with specific install/test commands
- bash node-coverage
# Start sonar scanner with appropriate settings
- dotnet sonarscanner begin
/n:"sonarqube-test"
/k:"sonarqube-test"
/d:sonar.login="${SONARQUBE_TOKEN}"
/d:sources=.
/d:sonar.typescript.lcov.reportPaths="$BITBUCKET_CLONE_DIR/src/coverage/lcov.info"
/d:sonar.javascript.lcov.reportPaths="$BITBUCKET_CLONE_DIR/src/coverage/lcov.info"
/d:sonar.cs.opencover.reportsPaths="$BITBUCKET_CLONE_DIR/coverage/opencovercoverage.xml"
/d:sonar.exclusions="**/node_modules/**,**/coverage/**,**/dist/**"
/d:sonar.test.inclusions="**/sonarqube-xunit-test/**,**/__tests__/**"
# Build C# project
- dotnet build
# Run C# tests and collect coverage
- bash dotnet-coverage
# End sonar scanner and upload results to sonarqube server
- dotnet sonarscanner end /d:sonar.login=${SONARQUBE_TOKEN}
definitions:
caches:
node: src/node_modules
This example features a single step build for C# projects with Sonar analysis and coverage. The sonar-scanner settings need to be configured at project start, to specify meta information about the project as well as the location of test coverage, excluded files and test inclusions. The $SONARQUBE token is defined as a global environment variable for the IT Minds Bitbucket.
All the scripts are added to the image PATH, and are accessible through bash script-name
dotnet-coverage
is used to trigger MiniCover code coverage as well as all csproj tests under the /test folder.node-coverage
is used to run npm or yarn test and install in all directories containing a package.json, it will prefer yarn if available. Make sure to enable code coverage and specify the coverage report paths in the project ymlgit-merge-master
is used on Bitbucket to merge master into the current branch that is being build. This is meant to be used in combination with is-pr to build and test on the result of the pull request.is-pr
is used on Bitbucket to check if there is an open pull request for the current branch being build. See the PR Example.This example features the complete yml for the sonarqube-test project in the IT Minds Bitbucket. It shows how is-pr and git-merge-master can be used.
# This is a sample build configuration for .NET Core.
# Only use spaces to indent your .yml configuration.
# -----
pipelines:
default:
- step:
name: Build .NET Core
image: itminds/aspnetcore-sonar-build
caches:
- node
- dotnetcore
script:
- export IS_PR=$(bash is-pr)
# if there is a PR open for the current branch, run test for post-merge result
- if [ $IS_PR == 'true' ]; then echo "PR detected, running test for post-merge result"; fi
- if [ $IS_PR == 'true' ]; then bash git-merge-master; fi
# Install and test js/ts. This script can be replaced with specific install/test commands
- bash node-coverage
# Build .NET Core with MSBuild Sonar Scanner active
- if [ $IS_PR == 'true' ]; then dotnet sonarscanner begin
/n:"sonarqube-test"
/k:"sonarqube-test"
/d:sonar.login="${SONARQUBE_TOKEN}"
/d:sources=.
/d:sonar.typescript.lcov.reportPaths="$BITBUCKET_CLONE_DIR/src/coverage/lcov.info"
/d:sonar.javascript.lcov.reportPaths="$BITBUCKET_CLONE_DIR/src/coverage/lcov.info"
/d:sonar.cs.opencover.reportsPaths="$BITBUCKET_CLONE_DIR/coverage/opencovercoverage.xml"
/d:sonar.exclusions="**/node_modules/**,**/coverage/**,**/dist/**"
/d:sonar.test.inclusions="**/sonarqube-xunit-test/**,**/__tests__/**"; fi
# Build C# project
- dotnet build
# If this is a PR, run coverage
- if [ $IS_PR == 'true' ]; then bash dotnet-coverage; fi
- if [ $IS_PR != 'true' ]; then echo 'Starting testing...' && dotnet test ./sonarqube-xunit-test/sonarqube-xunit-test.csproj || exit 1; fi
# Only update sonarcloud stats when it is a PR
- if [ $IS_PR == 'true' ]; then dotnet sonarscanner end /d:sonar.login=${SONARQUBE_TOKEN}; fi
branches:
master:
- step:
name: Build and test project (C# + js/ts)
image: itminds/aspnetcore-sonar-build
caches:
- node
- dotnetcore
script:
# Install and test js/ts. This script can be replaced with specific install/test commands
- bash node-coverage
# Start sonar scanner with appropriate settings
- dotnet sonarscanner begin
/n:"sonarqube-test"
/k:"sonarqube-test"
/d:sonar.login="${SONARQUBE_TOKEN}"
/d:sources=.
/d:sonar.typescript.lcov.reportPaths="$BITBUCKET_CLONE_DIR/src/coverage/lcov.info"
/d:sonar.javascript.lcov.reportPaths="$BITBUCKET_CLONE_DIR/src/coverage/lcov.info"
/d:sonar.cs.opencover.reportsPaths="$BITBUCKET_CLONE_DIR/coverage/opencovercoverage.xml"
/d:sonar.exclusions="**/node_modules/**,**/coverage/**,**/dist/**"
/d:sonar.test.inclusions="**/sonarqube-xunit-test/**,**/__tests__/**"
# Build C# project
- dotnet build
# Run C# tests and collect coverage
- bash dotnet-coverage
# End sonar scanner and upload results to sonarqube server
- dotnet sonarscanner end /d:sonar.login=${SONARQUBE_TOKEN}
definitions:
caches:
node: src/node_modules
Content type
Image
Digest
Size
578 MB
Last updated
about 8 years ago
docker pull itminds/aspnetcore-sonar-build