Skip to content

Commit e834acc

Browse files
authored
Display file content in sonarqube-jenkins (#26)
1 parent b8ceb71 commit e834acc

File tree

1 file changed

+9
-28
lines changed
  • docs/examples/jenkins/sonarqube-jenkins

1 file changed

+9
-28
lines changed

docs/examples/jenkins/sonarqube-jenkins/README.md

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: Tutorial on how to push code scanning results from Jenkins pipeline to SonarQube and how to display SonarQube data in Jenkins.
33
---
44

5-
# Jenkins and SonarQube
5+
# Integrating Jenkins and SonarQube
66

77
This example uses the same Jenkins configuration as the [Jenkins with access to hosts Docker engine](../jenkins-host-docker/) example. If you did any configuration in [jenkins-host-docker](../jenkins-host-docker/) directory, sync the project names with `-p`/`--project-name` option or `COMPOSE_PROJECT_NAME` environment variable to use the same volumes. For example:
88

@@ -17,6 +17,12 @@ export COMPOSE_PROJECT_NAME=jenkins
1717
docker compose up -d
1818
```
1919

20+
In additions to `jenkins` service, we now define a `sonarqube` service as well in the [docker-compose.yml](./docker-compose.yml):
21+
22+
```yaml title="docker-compose.yml"
23+
---8<--- "docs/examples/jenkins/sonarqube-jenkins/docker-compose.yml"
24+
```
25+
2026
## Gettings started with SonarQube
2127

2228
To get started with SonarQube, access the [Web UI](http://localhost:9000) and login with `admin:admin` credentials. Create a access token in [My account > Security](http://localhost:9000/account/security/) and store the token. Use this access token to authenticate to SonarQube from CI instead of the username and password combination.
@@ -43,33 +49,8 @@ First, install SonarQube Scanner plugin to your Jenkins instance through [Manage
4349

4450
After the SonarQube server is configured to Jenkins, sonar-scanner can be executed in a stage that uses the same [sonarsource/sonar-scanner-cli](https://hub.docker.com/r/sonarsource/sonar-scanner-cli) Docker image that was used in the previous step as well. This can be done with a stage level Docker agent:
4551

46-
```Groovy
47-
stage('Analyze') {
48-
agent {
49-
docker {
50-
image 'sonarsource/sonar-scanner-cli'
51-
// In order to be able to use http://sonarqube:9000 we need to be in the
52-
// same network as Jenkins and SonarQube are in.
53-
args '--net jenkins_default'
54-
// To guarantee that the workspace contains the sources pulled in previous
55-
// stage, we need to use the pipeline level workspace.
56-
reuseNode true
57-
}
58-
}
59-
steps {
60-
// The parameter must match the name you gave for the SonarQube server when
61-
// configuring it.
62-
withSonarQubeEnv('Sonar') {
63-
// Here, job name is used as the project key and current workspace as the
64-
// sources location.
65-
sh """
66-
sonar-scanner \
67-
-D'sonar.projectKey=${JOB_NAME}'\
68-
-D'sonar.sources=${WORKSPACE}'
69-
"""
70-
}
71-
}
72-
}
52+
```Groovy title="Jenkinsfile"
53+
---8<-- "docs/examples/jenkins/sonarqube-jenkins/Jenkinsfile"
7354
```
7455

7556
See [Jenkinsfile](./Jenkinsfile) for a example of a complete pipeline. If you try to execute this example pipeline replace `${GIT_URL}` with the URL to your git repository of choice.

0 commit comments

Comments
 (0)