|
| 1 | +# sonar-migration |
| 2 | +Command line tool to collect SonarQube data to prepare eventual migration to SonarCloud. |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +[](https://sonarcloud.io/dashboard?id=okorach_sonar-tools) |
| 11 | +[](https://sonarcloud.io/dashboard?id=okorach_sonar-tools) |
| 12 | +[](https://sonarcloud.io/dashboard?id=okorach_sonar-tools) |
| 13 | +[](https://sonarcloud.io/dashboard?id=okorach_sonar-tools) |
| 14 | + |
| 15 | +**DISCLAIMER**: This software is community software. |
| 16 | + |
| 17 | + |
| 18 | +# Requirements and Installation |
| 19 | +- `sonar-migration` requires python 3.8 or higher |
| 20 | +- Installation is based on [pip](https://pypi.org/project/pip/). |
| 21 | +- Online installation. |
| 22 | + - Run: `python3 -m pip install sonar-migration` (or `python3 -m pip upgrade sonar-migration`) |
| 23 | + If install does not behave as expected you can try the **pip** `--force-reinstall` option (see **pip** documentation) |
| 24 | +- `sonar-migration` is also available as a docker image. See [Using sonar-migration in Docker](#docker) |
| 25 | + |
| 26 | + |
| 27 | +# Common command line parameters |
| 28 | + |
| 29 | +All tools accept the following common parameters: |
| 30 | +- `-h` : Displays a help and exits |
| 31 | +- `-u` : URL of the SonarQube server. The default is environment variable `$SONAR_HOST_URL` |
| 32 | +or `http://localhost:9000` by default if the environment variable is not set |
| 33 | +- `-t` : Admin user token to invoke the SonarQube APIs, like `squ_83356c9b2db891d45da2a119a29cdc4d03fe654e`. |
| 34 | +The default is environment variable `$SONAR_TOKEN`. |
| 35 | +Using login/password is not possible. |
| 36 | +The user corresponding to the token must have sufficiently elevated permissions to achieve the tool tasks |
| 37 | +- `-f`: Define the output file, if not specified, `migration.<SERVER_ID>.json` is generated |
| 38 | +- `-o` : Organization, for SonarCloud - Ignored if running against a SonarQube instance |
| 39 | +- `-v` : Logging verbosity level (`WARN`, `ÌNFO` or `DEBUG`). The default is `INFO`. |
| 40 | +`ERROR` and above is always active. |
| 41 | +- `-c` or `--clientCert` : Allows to specify an optional client certificate file (as .pem file) |
| 42 | +- `--httpTimeout` : Sets the timeout for HTTP(S) requests to the SonarQube platform |
| 43 | +- `--skipVersionCheck` : `sonar-migration` occasionnally checks on pypi.org if there is a new version of **sonar-migration** available, and output a warning log if that is the case. You can skip this check with this option. |
| 44 | +- `-l <logFile>` : Send logs to **<logFile>**, stdout by default |
| 45 | + |
| 46 | +See common [error exit codes](#exit-codes) at the bottom of this page |
| 47 | + |
| 48 | +## Required Permissions |
| 49 | + |
| 50 | +To export data, `sonar-migration` needs elevated permissions |
| 51 | + |
| 52 | +## Examples |
| 53 | +``` |
| 54 | +export SONAR_HOST_URL=https://sonar.acme-corp.com |
| 55 | +export SONAR_TOKEN=squ_83356c9b2db891d45da2a119a29cdc4d03fe654e |
| 56 | +
|
| 57 | +# Exports all platform migration data from https://sonar.acme-corp.com in default output file migration.<SERVER_ID>.json |
| 58 | +sonar-migration |
| 59 | +
|
| 60 | +# Exports all platform migration data from https://sonar.acme-corp.com in file data.json |
| 61 | +sonar-migration -f data.json |
| 62 | +
|
| 63 | +
|
| 64 | +``` |
| 65 | + |
| 66 | +For more about what is exported and imported by `sonar-config` please see the [sonar-config complete documentation](https://github.com/okorach/sonar-tools/blob/master/doc/sonar-config.md) |
| 67 | + |
| 68 | +# <a name="docker"></a>Using sonar-migration in Docker |
| 69 | + |
| 70 | +`sonar-migration` is available as a docker image. Here is how to use the docker version: |
| 71 | +``` |
| 72 | +docker pull olivierkorach/sonar-migration:latest |
| 73 | +
|
| 74 | +docker run --rm -w `pwd` -v `pwd`:`pwd` sonar-migration -t $SONAR_TOKEN -u https://sonar.acme.com |
| 75 | +# After the command the file migratiob.<SERVER_ID>.json should be in the local (pwd) directory |
| 76 | +
|
| 77 | +# Alternatively you can pass the SonarQube URL and token as environment variables |
| 78 | +docker run --rm -w `pwd` -v `pwd`:`pwd` -e SONAR_TOKEN=<YOUR_SONAR_TOKEN> -e SONAR_HOST_URL=<YOUR_SONAR_URL> sonar-migration |
| 79 | +
|
| 80 | +# If you run sonar-migration on same machine as SonarQube, to help, the URL fragment http://localhost is automatically transformed in http://host.docker.internal, |
| 81 | +# For instance the 2 commands below have same outcome |
| 82 | +docker run --rm -w `pwd` -v `pwd`:`pwd` sonar-migration -t $SONAR_TOKEN -u http://host.docker.internal:9000 |
| 83 | +docker run --rm -w `pwd` -v `pwd`:`pwd` sonar-migration -t $SONAR_TOKEN -u http://localhost:9000 |
| 84 | +``` |
| 85 | + |
| 86 | +# <a name="exit-codes"></a>Exit codes |
| 87 | + |
| 88 | +When sonar-migration complete successfully they return exit code 0. En case of fatal error the following exit codes may be returned: |
| 89 | +- Code 1: Authentication error (Incorrect token provided) |
| 90 | +- Code 2: Authorization error (provided token has insufficient permissions) |
| 91 | +- Code 3: Other general Sonar API HTTP error |
| 92 | +- Code 4: No token provided |
| 93 | +- Code 5: Non existing project key provided |
| 94 | +- Code 6: - |
| 95 | +- Code 7: Unsupported operation requested (because of SonarQube edition or configuration) |
| 96 | +- Code 8: - |
| 97 | +- Code 9: - |
| 98 | +- Code 10: Incorrect command line arguments |
| 99 | +- Code 11: Global analysis or project analysis token provided (user token needed for sonar-tools) |
| 100 | +- Code 12: HTTP request time-out using the SonarQube API |
| 101 | +- Code 13: - |
| 102 | +- Code 14: Sonar connection error |
| 103 | +- Code 15: Miscellaneous OS errors |
| 104 | + |
| 105 | + |
| 106 | +# What's New - Release notes |
| 107 | + |
| 108 | +# Version 0.1 |
| 109 | + |
| 110 | +- First beta release |
| 111 | + |
| 112 | +# License |
| 113 | + |
| 114 | +Copyright (C) 2024 Olivier Korach |
| 115 | +mailto:olivier.korach AT gmail DOT com |
| 116 | + |
| 117 | +This program is free software; you can redistribute it and/or |
| 118 | +modify it under the terms of the GNU Lesser General Public |
| 119 | +License as published by the Free Software Foundation; either |
| 120 | +version 3 of the License, or (at your option) any later version. |
| 121 | + |
| 122 | +This program is distributed in the hope that it will be useful, |
| 123 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 124 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 125 | +Lesser General Public License for more details. |
| 126 | + |
| 127 | +You should have received a copy of the GNU Lesser General Public License |
| 128 | +along with this program; if not, write to the Free Software Foundation, |
| 129 | +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 commit comments