Skip to content

Commit ba5d08d

Browse files
authored
Separate-docs-for-each-tool (#2012)
* Remove links to local anchors. Point to GitHub instead * Update to follow common doc format * Added required permissions * Fixes #2006 * Add example with URL * Update CLI options details * Fix doc on --languages options (not -l) * remove docker doc left by mistake * Link to common parameters in GH * Update common parameters * Removed remaining relative links * Separate docker docs * Remove duplicate section
1 parent fbc1f97 commit ba5d08d

File tree

11 files changed

+509
-307
lines changed

11 files changed

+509
-307
lines changed

README.md

Lines changed: 37 additions & 290 deletions
Large diffs are not rendered by default.

doc/docker.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Using sonar-tools in Docker
2+
3+
Starting from version 3.4 `sonar-tools` is available as a docker image. Here is how to use the docker version:
4+
5+
## Installation
6+
7+
- Run: `docker pull olivierkorach/sonar-tools:latest` to install
8+
9+
## Usage
10+
11+
```
12+
docker pull olivierkorach/sonar-tools:latest
13+
# Run `docker run --rm olivierkorach/sonar-tools` followed by your usual sonar-tools command with its parameters, and example below for sonar-loc
14+
docker run --rm olivierkorach/sonar-tools sonar-loc -u <YOUR_SONAR_URL> -t <YOUR_SONAR_TOKEN> <parameters>
15+
16+
# Alternatively you can pass the Sonar(Qube/Cloud) URL and token as environment variables
17+
docker run --rm -e SONAR_TOKEN=<YOUR_SONAR_TOKEN> -e SONAR_HOST_URL=<YOUR_SONAR_URL> olivierkorach/sonar-tools sonar-loc <parameters>
18+
19+
# Trick if your SonarQube Server is on http://localhost, the URL to pass to docker is http://host.docker.internal, for instance:
20+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=http://host.docker.internal:9000 olivierkorach/sonar-tools
21+
22+
# The docker image contains all the sonar-tools. Here are other invocation examples
23+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-measures-export -k <projectKey> -m _all
24+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-findings-export -h
25+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-housekeeper -P 90 --mode dry-run --threads 4
26+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-projects-export
27+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-config -e --what projects
28+
```
29+
30+
Be aware that by default, files generated in the container are not available from the host. For files generated by sonar-tools you can either use stdout or volumes
31+
```
32+
# The below works, the file config.json is generated on the host
33+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-config -e > config.json
34+
35+
# The below doesn't work, the file config.json is generated in the container and, by default, not accessible from the host
36+
docker run --rm -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-config -e -f config.json
37+
38+
# If you want the 2nd form above to work you must use volumes, for instance:
39+
docker run --rm -w `pwd` -v `pwd`:`pwd` -e SONAR_TOKEN=$SONAR_TOKEN -e SONAR_HOST_URL=https://sonar.acme.com olivierkorach/sonar-tools sonar-config -e -f config.json
40+
# After the command the file config.json should be in the local (pwd) directory
41+
```

doc/sonar-audit.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
Command line tool to audit a SonarQube instance and output warning logs whenever a suspicious or incorrect setting/situation is found.
44
The detail of what is audited is listed at the bottom of this page
55

6-
## Requirements and Installation
6+
## Required Permissions
77

8-
`sonar-audit` is installed through the **sonar-tools** [general installation](../README.md#install)
8+
`sonar-audit` needs `Browse` and `Administer` permission on more or less everything that may be audited
9+
10+
## Requirements and Installation
911

10-
:warning: **sonar-tools** 2.7 or higher is required for `sonar-audit` compatibility with SonarQube 10
12+
`sonar-audit` is installed through the **sonar-tools** [general installation](https://github.com/okorach/sonar-tools/blob/master/README.md#install)
1113

1214
## Common command line parameters
1315

14-
`sonar-audit` accepts all the **sonar-tools** [common parameters](../README.md#common-params)
16+
`sonar-audit` accepts all the **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
1517

1618
## Usage
1719

18-
`sonar-audit [-u <url>] [-t <token>] [--what <auditSelection>] [--sif <SIF>] [-f <file>] [--format [json|csv]] [-h] [-v <debugLevel>]`
20+
`sonar-audit [--what <auditSelection>] [--sif <SIF>] [-f <file>] [--format [json|csv]]`
1921

2022
`--what` can be followed by a list of comma separated items to audit.
2123
When `--what` is not specified, everything is audited
@@ -37,11 +39,7 @@ When `--what` is not specified, everything is audited
3739
- `--format [json|csv]`: Generates output in JSON or CSV format (CSV is the default)
3840
- `--csvSeparator <separator>`: Allows to select the separator character for CSV, `,` is the default
3941
- `-h`: Displays help and exits
40-
- `-u`, `-t`, `-h`, `-v`, `--httpTimeout`, `--threads`: See **sonar-tools** [common parameters](../README.md#common-params)
41-
42-
## Required Permissions
43-
44-
To be able to audit everything, the token provided to `sonar-audit` should have the global `Administer System` permission and `Browse`and `Administer` permission on all projects.
42+
- `-h`, `-u`, `-t`, `-o`, `-v`, `-l`, `--httpTimeout`, `--threads`, `--clientCert`: See **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
4543

4644
## Configuration file
4745

doc/sonar-config.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ During import:
88
- When the object already exists it is updated according to the config file
99
- When an object exists in the target platform and is not defined in the config file, this object remains unmodified. As such the import of configuration is "additive" to the current config, it does not replace it.
1010

11+
## Required Permissions
12+
13+
`sonar-config` needs `Browse` and `Administer` permission on more or less everything that may be exported or imported
14+
1115
## Requirements and Installation
1216

13-
`sonar-config` is installed through the **sonar-tools** [general installation](../README.md#install)
17+
`sonar-config` is installed through the **sonar-tools** [general installation](https://github.com/okorach/sonar-tools/blob/master/README.md#install)
1418

1519
## Common command line parameters
1620

17-
`sonar-config` accepts all the **sonar-tools** [common parameters](../README.md#common-params)
21+
`sonar-config` accepts all the **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
1822

1923
## Usage
2024

21-
`sonar-config [-u <url>] [-t <token>] [-e|--export] [-i|--import] [-w|--what <configSelection>] [-f <file>] [-h] [-v <debugLevel>] [-k "<key1>,<key2>,...,<keyn>"]`
25+
`sonar-config [-e|--export] [-i|--import] [-w|--what <configSelection>] [-f <file>] [-h] [-k "<key1>,<key2>,...,<keyn>"]`
2226

2327
`--what` can be followed by a list of comma separated items to export or import
2428
When `--what` is not specified, everything is exported or
@@ -36,7 +40,7 @@ When `--what` is not specified, everything is exported or
3640
- `-k "<key1>,<key2>,...,<keyn>"`: Limits the export or import operation to projects, apps or portfolios matching these keys
3741
- `--fullExport`: Will also export object properties that are not used for an import by may be of interest anyway
3842
- `-h`: Displays help and exits
39-
- `-u`, `-t`, `-h`, `-v`: See **sonar-tools** [common parameters](../README.md#common-params)
43+
- `-h`, `-u`, `-t`, `-o`, `-v`, `-l`, `--httpTimeout`, `--threads`, `--clientCert`: See **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
4044

4145
## Required Permissions
4246

doc/sonar-findings-export.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# sonar-findings-export
2+
(Also available as `sonar-issues-export` for backward compatibility, but **deprecated**)
3+
4+
Exports a list of issues as CSV, JSON or SARIF format. The export is sent to standard output or into a file
5+
Plenty of issue filters can be specified from the command line, type `sonar-findings-export -h` for details.
6+
:warning: On large SonarQube Server or Cloud instances with a lot of issues, it can be stressful for the instance (many API calls) and very long to export all issues. It's recommended to define filters that will only export a subset of all issues (see examples below).
7+
8+
Basic Usage: `sonar-findings-export [--format csv|json|sarif] [--sarifNoCustomProperties] [-k <keyList>] ...`
9+
10+
- `--format csv|json|sarif`: Choose export format. Default is based on output file extension, and csv in last - `--sarifNoCustomProperties`: For SARIF export. By default all Sonar custom properties are exported which makes the SARIF export quite verbose. Use this option to not export the Sonar custom properties (only the SARIF standard ones)
11+
- `--statuses <statusList>`: Only export findings with given statuses, comma separated among OPEN,CONFIRMED,REOPENED,RESOLVED,CLOSED,TO_REVIEW,REVIEWED
12+
- `--resolutions <resolutionList>`: Only export findings with given resolution, comma separated among FALSE-POSITIVE,WONTFIX,FIXED,REMOVED,ACCEPTED,SAFE,ACKNOWLEDGED,FIXED
13+
- `--severities <severityList>`: Only export findings with given resolution, comma separated among BLOCKER,CRITICAL,MAJOR,MINOR,INFO
14+
- `--types <typeList>`: Only export findings with given type, comma separated among BUG,VULNERABILITY,CODE_SMELL,SECURITY_HOTSPOT
15+
- `--createdAfter <YYYY-MM-DD>`: Only export findings created after a given date
16+
- `--createdBefore <YYYY-MM-DD>`: Only export findings created before a given date
17+
- `--tags <tagList>`: Comma separated list of tags corresponding to issues
18+
- `--languages <languageList>`: Comma separated list of languages from whom findings should be exported
19+
- `--useFindings`: Use SonarQube Server `api/projects/export_findings` whenever possible, No effect with SonarQube Cloud
20+
- `-k <keyList>`: Comma separated list of keys of objects to export (all objects if not specified)
21+
- `-b <branchList>`: For projects and apps, comma separated list of branches to export (Use * for all branches)
22+
- `--datesWithoutTime`: Reports timestamps only with date, not time
23+
- `-h`, `-u`, `-t`, `-o`, `-v`, `-l`, `--httpTimeout`, `--threads`, `--clientCert`: See **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
24+
25+
26+
## Required Permissions
27+
28+
`sonar-findings-export` needs `Browse` permission on all projects, applications or portfolios for which findings are exported
29+
30+
## Requirements and Installation
31+
32+
`sonar-findings-export` is installed through the **sonar-tools** [general installation](https://github.com/okorach/sonar-tools/blob/master/README.md#install)
33+
34+
## Common command line parameters
35+
36+
`sonar-config` accepts all the **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
37+
38+
## Examples
39+
```
40+
export SONAR_HOST_URL=https://sonar.acme-corp.com
41+
export SONAR_TOKEN=squ_83356c9b2db891d45da2a119a29cdc4d03fe654e
42+
43+
# Exports all issues (main branch). This can be very long and stressful for SonarQube APIs
44+
sonar-findings-export >all_issues.csv
45+
46+
# Exports all issues of project myProjectKey
47+
sonar-findings-export -k myProjectKey -f project_issues.csv
48+
49+
# Exports all false positive and won't fix issues across all projects
50+
sonar-findings-export -r FALSE-POSITIVE,WONTFIX -f fp_wf.json
51+
52+
# Exports all issues created in 2020
53+
sonar-findings-export -a 2020-01-01 -b 2020-12-31 -f issues_created_in_2020.csv
54+
55+
# Exports all vulnerabilities and bugs
56+
sonar-findings-export -types VULNERABILITY,BUG --format json >bugs_and_vulnerabilities.json
57+
58+
# Exports all vulnerabilities and bugs in SARIF format
59+
sonar-findings-export -types VULNERABILITY,BUG --format sarif >bugs_and_vulnerabilities.sarif.json
60+
61+
# Export all findings of project myProjectKey in SARIF format without the custom Sonar properties
62+
sonar-findings-export -k myProjectKey ----sarifNoCustomProperties -f myProjectKey.sarif
63+
```

doc/sonar-findings-sync.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ When the source or target is a Community Edition/Build then only the main branch
77

88
## Requirements and Installation
99

10-
`sonar-findings-sync` is installed through the **sonar-tools** [general installation](../README.md#install)
10+
`sonar-findings-sync` is installed through the **sonar-tools** [general installation](https://github.com/okorach/sonar-tools/blob/master/README.md#install)
1111

1212
## Common command line parameters
1313

14-
`sonar-findings-sync` accepts all the **sonar-tools** [common parameters](../README.md#common-params)
14+
`sonar-findings-sync` accepts all the **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
1515

1616
## Usage
1717

@@ -30,7 +30,8 @@ When the source or target is a Community Edition/Build then only the main branch
3030
the target token.
3131
- `--nolink`: Do not add a HTTP link comment in the source and target findings (that point at each other)
3232
- `--tag`: Defines the tag applied to synchronized issues, default is `synchronized`. Use `--tag ''` to not tag the issues
33-
- `-u`, `-t`, `-h`, `-v`: See **sonar-tools** [common parameters](../README.md#common-params)
33+
- `-h`, `-u`, `-t`, `-o`, `-v`, `-l`, `--httpTimeout`, `--threads`, `--clientCert`: See **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
34+
3435

3536
:warning: Note about `-t` and `-T`: It is **strongly recommended** to run `sonar-findings-sync` with the credentials of a specific service account dedicated to issues synchronization on the target. This will allow to recognize automatic synchronization changes by the author of those changes. This token is either the one provided with `-t` when the synchronization is within the same SonarQube Server or Cloud (for instance 2 branches of a same project), or `-T` when synchronizing between 2 different SonarQube Server or Cloud instances (The `-T <token>` corresponding to a user on the **target** SonarQube Server or Cloud in that case)
3637

doc/sonar-housekeeper.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# <a name="sonar-housekeeper">
2+
3+
Deletes obsolete/outdated data from SonarQube:
4+
- Projects whose last analysis date (on any branch) is older than a given number of days.
5+
- User tokens older than a given number of days
6+
- Inactive branches (Branches not analyzed for a given number of days), excepted branches marked as "keep when inactive"
7+
- Inactive pull requests (PRs not analyzed for a given number of days)
8+
9+
Usage: `sonar-housekeeper [-P <days>] [-B <days>] [-R <days>] [-T <days>] [--mode delete]`
10+
11+
- `-P <days>`: Will search for projects not analyzed since more than `<days>` days.
12+
To avoid deleting too recent projects it is denied to specify less than 90 days
13+
- `-B <days>`: Will search for projects branches not analyzed since more than `<days>` days.
14+
Branches marked as "keep when inactive" are excluded from housekeeping
15+
- `-R <days>`: Will search for pull requests not analyzed since more than `<days>` days
16+
- `-T <days>`: Will search for tokens created since more than `<days>` days
17+
- `--mode delete`: If not specified, `sonar-housekeeper` will only perform a dry run and list projects
18+
branches, pull requests and tokens that would be deleted.
19+
If `--mode delete` is specified objects are actually deleted
20+
- `-h`, `-u`, `-t`, `-o`, `-v`, `-l`, `--httpTimeout`, `--threads`, `--clientCert`: See **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
21+
22+
23+
:warning: **sonar-tools** 2.7 or higher is required for `sonar-housekeeper` compatibility with SonarQube Server 10
24+
25+
## Required Permissions
26+
27+
To be able to delete anything, the token provided to `sonar-housekeeper` should have:
28+
- The global `Administer System` permission to delete tokens
29+
- Plus `Browse` and `Administer` permission on all projects to delete (or with branches or PR to delete)
30+
31+
## Requirements and Installation
32+
33+
`sonar-housekeeper` is installed through the **sonar-tools** [general installation](https://github.com/okorach/sonar-tools/blob/master/README.md#install)
34+
35+
## Common command line parameters
36+
37+
`sonar-housekeeper` accepts all the **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
38+
39+
### :information_source: Limitations
40+
To avoid bad mistakes (mistakenly deleting too many projects), the tools will refuse to delete projects analyzed in the last 90 days.
41+
42+
### :warning: Database backup
43+
**A database backup should always be taken before executing this script. There is no recovery.**
44+
45+
### Example
46+
```
47+
sonar-housekeeper -u https://sonar.acme-corp.com -t 15ee09df11fb9b8234b7a1f1ac5fce2e4e93d75d
48+
```

doc/sonar-loc.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# sonar-loc
2+
3+
Exports all projects lines of code as they would be counted by the commercial licences.
4+
See `sonar-loc -h` for details
5+
6+
Basic Usage: `sonar-loc [-f <file>] [--format csv|json] [-a] [-n] [--withTags] [--withURL] [--apps] [--portfolios] [--topLevelOnly]`
7+
- `-f`: Define file for output (default stdout). File extension is used to deduct expected format (json if file.json, csv otherwise)
8+
- `--format`: Choose export format between csv (default) and json
9+
- `--projects`: Output the LOC of projects (this is the default if nothing specified)
10+
- `--apps`: Output the LOC of applications (Developer and higher editions)
11+
- `--portfolios`: Output the LOC of portfolios (Enterprise and higher editions)
12+
- `--topLevelOnly`: For portfolios, only output LoCs for top level portfolios (Enterprise Edition only)
13+
- `-n | --withName`: Outputs the project or portfolio name in addition to the key
14+
- `-a | --withLastAnalysis`: Output the last analysis date (all branches and PR taken into account) in addition to the LOCs
15+
- `--withTags`: Outputs the tags of the project, app or portfolio
16+
- `--withURL`: Outputs the URL of the project, app or portfolio for each record
17+
- `-b`: Export LoCs for each branches of targeted objects (projects or applications)
18+
- `-h`, `-u`, `-t`, `-o`, `-v`, `-l`, `--httpTimeout`, `--threads`, `--clientCert`: See **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
19+
20+
## Required Permissions
21+
22+
`sonar-loc` needs `Browse` permission on all projects of the Server or Cloud instance
23+
24+
## Requirements and Installation
25+
26+
`sonar-loc` is installed through the **sonar-tools** [general installation](https://github.com/okorach/sonar-tools/blob/master/README.md#install)
27+
28+
## Common command line parameters
29+
30+
`sonar-loc` accepts all the **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)

0 commit comments

Comments
 (0)