-
Notifications
You must be signed in to change notification settings - Fork 39
Update sonar evidence example #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
788e68f
Update sonar integration example
mnsboev 13cfec4
Merge pull request #79 from mnsboev/sonar-example
mnsboev 4db08ab
Fix sonar-evidence-example.yml formatting
mnsboev d3377f6
Refactor sonar-evidence-example.yml for improved formatting and cleanup
mnsboev a6203ac
Refactor sonar-evidence-example.yml for improved formatting and cleanup
mnsboev 3fb6480
Add SONAR_TOKEN environment variable for evidence creation step in so…
mnsboev 815baa7
Add SONAR_REPORT_TASK_PATH environment variable for evidence creation…
mnsboev 5a70543
Rename SONAR_REPORT_TASK_PATH to SONAR_REPORT_TASK_FILE in sonar-evid…
mnsboev 0cf1360
Update README.md to enhance Sonar evidence creation documentation
mnsboev e9d9d95
Update README.md to reflect changes in key and key-alias for Sonar in…
mnsboev 28a56b4
Update README.md to simplify SONAR_TOKEN description
mnsboev 1dcd38a
Fix YAML path in README.md for Sonar integration configuration
mnsboev 7fdb1b4
Fix YAML path in README.md for Sonar integration configuration
mnsboev f2d82ab
Update sonar-evidence-example.yml to correct integration command form…
mnsboev b49cea3
Update sonar-evidence-example.yml to change key-alias variable for in…
mnsboev e52ea49
Update sonar-evidence-example.yml to change key-alias variable for in…
mnsboev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,61 +1,75 @@ | ||
| # Create Sonar Scan Evidence predicate from the build CI and attach it to the build info | ||
| Sonar is a code scanning tool that helps to identify bugs, vulnerabilities, and code smells in your code. | ||
| It is important to track the code quality and security of the code changes done and released. | ||
| To allow automation of proper code quality and security checks, we create an evidence of the Sonar scan results | ||
| during the build with confirmation that the code quality and security checks passed before the code was committed. | ||
| using the `FailOnAnalysisFailure` argument the customer can decide if to create the sonar scan evidence if the scan did not pass | ||
| sonar quality gates, or fail the predicate creation with exist status 1. | ||
| If the Analysis status is not 'OK', but `FailOnAnalysisFailure` was not set, then the predicate is created with analysis.status = 'ERROR' which | ||
| should be checked using a policy. | ||
|
|
||
| ## Environment variables | ||
| - `SONAR_TOKEN` - The sonar server token. | ||
| - `SONAR_TYPE` - Should be Either SAAS or SELFHOSTED, defaulting to SAAS. | ||
| - `SONAR_HOST_URL` - The sonar server host name, for example https://mysonar.mycorp.com, for example sonar.myconpany.org. required for SELFHOSTED type, if not provided for SAAS type sonarcloud.io is used as default. | ||
| - `SONAR_PROXY_URL` - The proxy server URL, in the format of http://your-proxy-server:port. or https://username:password@your-proxy-server:port | ||
|
|
||
| ## Arguments | ||
| `--reportTaskFile=<path>` - The path to the sonar report task file. | ||
| `--FailOnAnalysisFailure` - Fail with exit code 1 if the sonar analysis failed in sonar quality gate. | ||
| `--WaitTime=<seconds>` - between sonar analysis results checks> | ||
| `--MaxRetries=<number>` - The maximum number of retries to check the sonar analysis results. | ||
| `--UseProxy` - Use a proxy server URL, requires PROXY_URL environment variable to be set. | ||
|
|
||
| ## The example is based on the following steps: | ||
| 1. set sonar token as an environment variable | ||
| 2. call sonar scan | ||
| for example: | ||
| `` | ||
| $PWD/sonar-scanner-6.2.1.4610/bin/sonar-scanner \ | ||
| -Dsonar.projectKey=my-sonar-project-key \ | ||
| -Dsonar.organization=my-sonar-org \ | ||
| -Dsonar.host.url=https://sonarcloud.io \ | ||
| -Dsonar.java.jdkHome=$JAVA_HOME \ | ||
| -Dsonar.verbose=true \ | ||
| -Dsonar.token=$SONAR_TOKEN | ||
| `` | ||
| 3. call the jira-transition-checker utility (use the binary for your build platform) with these arguments: "transition name" JIRA-ID [,JIRA-ID] | ||
| for example: | ||
| ``./examples/sonar-scan/bin/sonar-scan-extractor-linux-amd64 --reportTaskFile=$PWD/.scannerwork/report-task.txt --FailOnAnalysisFailure > predicate.json | ||
| `` | ||
| 4. call the evidence create cli with the predicate.json file | ||
| for example: | ||
| `` | ||
| jf evd create \ | ||
| --build-name $GITHUB_WORKFLOW \ | ||
| --build-number "${{ github.run_number }}" \ | ||
| --predicate ./predicate.json \ | ||
| --predicate-type https://jfrog.com/evidence/sonar-scan/v1 \ | ||
| --provider-id "sonar" \ | ||
| --key "${{ secrets.JIRA_TEST_PKEY }}" \ | ||
| --key-alias ${{ vars.JIRA_TEST_KEY }} | ||
| `` | ||
|
|
||
| ## Additional considerations | ||
| ```plaintext | ||
| It is advised to decide if to create an evidence with sonar analysis failure scan or refrain from creating the evidence. | ||
| to create the evidence with an analysis gateway failure content, do **not** add the `--FailOnAnalysisFailure` argument. | ||
|
|
||
| to refrain from creating the evidence with an analysis gateway failure content, add the `--FailOnAnalysisFailure` argument. | ||
| then check the exit code of the script and decide if to create the evidence or not. | ||
| ``` | ||
| ## Sonar evidence creation | ||
|
|
||
| This example shows how to create and attach Sonar analysis evidence using the JFrog CLI. | ||
|
|
||
| ### Prerequisites | ||
| - SONAR_TOKEN: SonarCloud/SonarQube token. | ||
| - A completed Sonar scan that produced a `report-task.txt` file. | ||
|
|
||
| ### Default report-task.txt discovery | ||
| When you run: | ||
| ```bash | ||
| jf evd create --integration sonar | ||
| ``` | ||
| the tool auto-detects the Sonar task file using these paths (in order): | ||
| - target/sonar/report-task.txt (Maven) | ||
| - build/sonar/report-task.txt (Gradle) | ||
| - .scannerwork/report-task.txt (CLI scanner) | ||
| - .sonarqube/out/.sonar/report-task.txt (MSBuild) | ||
|
|
||
| If the file is not found, configure its location via YAML or env var (see below). | ||
|
|
||
| ### Minimal workflow step (example) | ||
| ```yaml | ||
| - name: Create evidence | ||
| env: | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| run: | | ||
| jf evd create \ | ||
| --build-name $GITHUB_WORKFLOW \ | ||
| --build-number "${{ github.run_number }}" \ | ||
| --key "${{ secrets.SIGNING_KEY }}" \ | ||
| --key-alias ${{ vars.SIGNING_KEY_ALIAS }} \ | ||
| --integration sonar | ||
| ``` | ||
|
|
||
| ### Configuration | ||
| You can configure the integration via YAML or environment variables. YAML keys have 1:1 env equivalents. | ||
|
|
||
| 1) YAML: .jfrog/evidence/evidence.yml | ||
| ```yaml | ||
| sonar: | ||
| url: https://sonarcloud.io | ||
| reportTaskFile: .scannerwork/report-task.txt | ||
| pollingMaxRetries: 30 | ||
| pollingRetryIntervalMs: 5000 | ||
| ``` | ||
|
|
||
| 2) Environment variables | ||
| - SONAR_URL | ||
| - SONAR_REPORT_TASK_FILE | ||
| - SONAR_POLLING_MAX_RETRIES | ||
| - SONAR_POLLING_RETRY_INTERVAL_MS | ||
|
|
||
| ### Parameters reference | ||
| Evidence creation: | ||
|
|
||
| - --integration sonar | ||
| - Selects the Sonar integration. | ||
|
|
||
| Sonar resolution (via YAML/env): | ||
|
|
||
| - sonar.url / SONAR_URL | ||
| - Sonar base URL. By default url is parsed from report-task.txt. If not found there, defaults to https://sonarcloud.io. | ||
|
|
||
| - sonar.reportTaskFile / SONAR_REPORT_TASK_FILE | ||
| - Path to report-task.txt. If omitted, auto-detection (see order above) is used. | ||
|
|
||
| - sonar.pollingMaxRetries / SONAR_POLLING_MAX_RETRIES | ||
| - Maximum polling attempts to wait for analysis results. | ||
|
|
||
| - sonar.pollingRetryIntervalMs / SONAR_POLLING_RETRY_INTERVAL_MS | ||
| - Milliseconds to wait between polling attempts. | ||
|
|
||
| ### Behavior | ||
| Evidence is created for both successful and failed Sonar analyses (including failed quality gates). |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.