docker中的jenkins去配置sonarQube
1、拉取sonarQube
bash
macdeMacBook-Pro:~ mac$ docker pull sonarqube:8.9.6-community
8.9.6-community: Pulling from library/sonarqube
8572bc8fb8a3: Pull complete
702f1610d53e: Pull complete
8c951e69c28d: Pull complete
f95e4f8c4082: Pull complete
0ac9ebcbeda3: Pull complete
Digest: sha256:bef2a81963ccf2f3de0d793c172e4e343e55b9c6b0322dc610e427bc6f566799
Status: Downloaded newer image for sonarqube:8.9.6-community
docker.io/library/sonarqube:8.9.6-community
What's Next?
View summary of image vulnerabilities and recommendations → docker scout quickview sonarqube:8.9.6-community
2、拉取postgres
bash
macdeMacBook-Pro:~ mac$ docker pull postgres
Using default tag: latest
latest: Pulling from library/postgres
648e0aadf75a: Pull complete
f715c8c55756: Pull complete
b11a1dc32c8c: Pull complete
f29e8ba9d17c: Pull complete
78af88a8afb0: Pull complete
b74279c188d9: Pull complete
6e3e5bf64fd2: Pull complete
b62a2c2d2ce5: Pull complete
eba91ca3c7a3: Pull complete
d4a24cdf2433: Pull complete
b20f8a8dfd5c: Pull complete
e0731dd084c3: Pull complete
0361da6a228e: Pull complete
Digest: sha256:8775adb39f0db45cf4cdb3601380312ee5e9c4f53af0f89b7dc5cd4c9a78e4e8
Status: Downloaded newer image for postgres:latest
docker.io/library/postgres:latest
What's Next?
View summary of image vulnerabilities and recommendations → docker scout quickview postgres
3、编写docker-compose.yml
yml
version: '3.1'
services:
db:
image: postgres
container_name: db
ports:
- 5432:5432
networks:
- sonarnet
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
sonarqube:
image: sonarqube:8.9.6-community
container_name: sonarqube
depends_on:
- db
ports:
- 9000:9000
networks:
- sonarnet
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
networks:
sonarnet:
driver: bridge
4、启动
bash
macdeMacBook-Pro:sonarqube mac$ docker-compose up -d
[+] Running 3/3
✔ Network sonarqube_sonarnet Created 0.0s
✔ Container db Started 0.4s
✔ Container sonarqube Started
5、打开页面并配置新密码
默认是
admin
admin
6、jenkins下载插件
sonarQube Scanner
7、配置jenkins
这里Server authentication token需要取sonarQube中获取token
8、jenkins的项目中配置
之后将他移到构建之前
bash
sonar.projectname=${JOB_NAME}
sonar.projectKey=${JOB_NAME}
sonar.source=./
sonar.java.binaries=target
9、开始构建
我构建的时候会报一个这样的错误,跟我之前访问docker中的oracle数据库应该是同样的错误,无法访问宿主机的localhost
lMac:docker.for.mac.host.internal
Linux:host.docker.internal
可以看我之前的文章https://blog.csdn.net/weixin_48319193/article/details/132124664?spm=1001.2014.3001.5501
之后我将localhost换成
bash
sonar.host.url=http://docker.for.mac.host.internal:9000
sonar.projectname=${JOB_NAME}
sonar.projectKey=${JOB_NAME}
sonar.source=./
sonar.java.binaries=target