-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SC-1063 provide orb that adds support for SonarCloud in CircleCI
- Loading branch information
1 parent
6bb66df
commit 0d45fc5
Showing
7 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
version: 2.1 | ||
orbs: | ||
orb-tools: circleci/[email protected] | ||
sonarcloud: sonarsource/sonarcloud@dev:alpha | ||
jobs: | ||
test: | ||
parameters: | ||
image: | ||
type: string | ||
docker: | ||
- image: <<parameters.image>>:latest | ||
steps: | ||
- checkout | ||
- sonarcloud/scan | ||
workflows: | ||
publish-dev: | ||
jobs: | ||
- orb-tools/pack: | ||
source-dir: src/main | ||
destination-orb-path: orb.yml | ||
workspace-path: orb.yml | ||
artifact-path: orb.yml | ||
- orb-tools/publish-dev: | ||
context: Publishing Orb | ||
orb-name: sonarsource/sonarcloud | ||
requires: [orb-tools/pack] | ||
- test: | ||
name: test-node | ||
image: node | ||
context: SonarCloud Analysis | ||
requires: [orb-tools/publish-dev] | ||
- test: | ||
name: test-circleci-python | ||
image: circleci/python | ||
context: SonarCloud Analysis | ||
requires: [orb-tools/publish-dev] | ||
- orb-tools/publish: | ||
context: Publishing Orb | ||
orb-ref: sonarsource/[email protected] | ||
attach-workspace: true | ||
requires: [test-node, test-circleci-python] | ||
filters: | ||
branches: | ||
only: master | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Eclipse | ||
.classpath | ||
.project | ||
.settings | ||
|
||
# Gradle | ||
build/ | ||
.gradle/ | ||
.gradletasknamecache | ||
classes/ | ||
out/ | ||
|
||
# IntelliJ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
.idea/ | ||
|
||
# Maven | ||
target/ | ||
|
||
# Mac OS X | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
Icon | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
# MSWindows | ||
Thumbs.db | ||
ehthumbs.db | ||
Desktop.ini | ||
$RECYCLE.BIN/ | ||
|
||
# NPM/yarn | ||
npm-debug.log* | ||
npm.tar.gz | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# SonarQube/SonarCloud | ||
.sonar/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
# sonarcloud-circleci-orb | ||
Support of SonarScanner CLI in CircleCI | ||
|
||
## SonarCloud Orb | ||
The SonarCloud Orb can be used with any linux based docker image that includes the command line tools `curl` and `unzip`. | ||
|
||
To connect to your SonarCloud project on `sonarcloud.io` you need to setup an api token. We recommend to setup a CircleCI context in your organization named `sonarcloud` that contains a variable with key `SONAR_TOKEN` and the api token as the value. | ||
### Usage examples | ||
```yaml | ||
version: 2.1 | ||
orbs: | ||
sonarcloud: sonarsource/[email protected] | ||
jobs: | ||
build: | ||
docker: | ||
- image: 'circleci/python:3.7.4' | ||
steps: | ||
- checkout | ||
- sonarcloud/scan | ||
workflows: | ||
my-workflow: | ||
jobs: | ||
- build: | ||
context: sonarcloud | ||
``` | ||
### Publishing a new version | ||
To publish a new version of the orb you need to change the version found in .circleci/config.yml to the new version. The CirceCI build pipeline will then publish the new version of the orb. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sonar.projectKey=SonarSource_sonarcloud-circleci-orb | ||
sonar.projectName=sonarcloud-circleci-orb | ||
sonar.projectVersion=1.0 | ||
sonar.sources=. | ||
sonar.organization=sonarsource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version: 2.1 | ||
description: Detect bugs and vulnerabilities in your repository |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
description: Detect bugs and vulnerabilities | ||
parameters: | ||
sonar_token_variable_name: | ||
description: the name of the environment variable where the SonarCloud API token is stored | ||
default: SONAR_TOKEN | ||
type: env_var_name | ||
cache_version: | ||
description: increment this value if the cache is corrupted and you want to start with a clean cache | ||
default: 1 | ||
type: integer | ||
steps: | ||
- run: | ||
name: Create cache directory if it doesn't exist | ||
command: mkdir -p /tmp/cache/scanner | ||
- restore_cache: | ||
keys: | ||
- v<<parameters.cache_version>>-sonarcloud-scanner-4.1.0.1829 | ||
- run: | ||
name: SonarCloud | ||
command: | | ||
set -e | ||
VERSION=4.1.0.1829 | ||
SONAR_TOKEN=$<<parameters.sonar_token_variable_name>> | ||
SCANNER_DIRECTORY=/tmp/cache/scanner | ||
export SONAR_USER_HOME=$SCANNER_DIRECTORY/.sonar | ||
OS="linux" | ||
echo $SONAR_USER_HOME | ||
if [[ ! -x "$SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/bin/sonar-scanner" ]]; then | ||
curl -Ol https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$VERSION-$OS.zip | ||
unzip -qq -o sonar-scanner-cli-$VERSION-$OS.zip -d $SCANNER_DIRECTORY | ||
fi | ||
chmod +x $SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/bin/sonar-scanner | ||
chmod +x $SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/jre/bin/java | ||
$SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/bin/sonar-scanner | ||
environment: | ||
SONARQUBE_SCANNER_PARAMS: '{"sonar.host.url":"https://dogfood-core.sc-dev.io"}' | ||
- save_cache: | ||
key: v<<parameters.cache_version>>-sonarcloud-scanner-4.1.0.1829 | ||
paths: /tmp/cache/scanner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
description: Use the sonarcloud orb to detect bugs and vulnerabilities in your repository | ||
usage: | ||
version: 2.1 | ||
jobs: | ||
build: | ||
docker: | ||
- image: node:latest | ||
steps: | ||
- checkout | ||
- sonarcloud/scan | ||
orbs: | ||
sonarcloud: sonarsource/[email protected] | ||
workflows: | ||
main: | ||
jobs: | ||
- build: | ||
context: sonarcloud |