- Download Jenkins in local folder (C:\software\jenkins) and run
- Admin user
- user name: Admin
- password: D:\Users<username>.jenkins\secrets\initialAdminPassword
- User/password: [user name]/[password]
- Start jenkins
- java -jar jenkins.war --httpPort=8080
- Access jenkins: http://localhost:8080
- Manage Jenkins > Configure Global Security
- Plugin Manage > check "Use browser for metadata download"
- Manage Jenkins > Manage Plugins > Advanced
- Values
- Server: [proxy server]
- Port: [port]
- User name: [Blank]
- Password: [Blank]
- Validate Proxy > Test URL(http://google.com/)
- Click Submit
- Click Check Now; this will give error if last step(Configure Global Security) is not done
- Install plugin
- Manage Jenkins > Manage Plugins > Available > search "Git plugin"
- Install without restart
- Create Global credential
- Jenkins> Credentials> Sytem> Global Credentials
- Kind: Username with password
- Scope: Global
- UserName:[git user name]
- Password: [git Personal access token]
- Create new Jenkins job
- Dashboard > New Item > Freestyle project
- Source code management
- Git
- Repository URL: [URL of your repo]
- Credentails: [Global credential created earlier]
- Error
- If Git URL throws error like - "failed to connect to repository, returned status code 128"
- Add git server host(like github.com) in jenkins HTTP Proxy Configuration >No Proxy Host
- Manage Jenkins > Global Tool Configuration > Add Maven
- Uncheck "Install Automatically"
- Maven Name: Maven [Any name can be provided]
- MAVEN_HOME: [absolute path of maven installation like C:\apache-maven-3.2.5]
- Trigger build
- Select the project > Build Trigger
- Select "Poll SCM"
- Schedule # every fifteen minutes (perhaps at :07, :22, :37, :52) H/15 * * * *
- Add maven build in project
- Select the project
- Got to 'Configure' > Build
- Select "Invoke top-level Maven targets"
- Maven Version: Maven [Maven name provided in earlier step]
- Goal: clean package
-
Jenkins and SonarQube should be on the same server
-
SonarQube scanner
- Manage Jenkins > Global Tool Configuration > SonarQube Scanner
- Name: SonarQube Scanner
- Check Install Automatically
-
SonarQube server
- Manage Jenkins > Configure System > sonarqube servers > Add SonarQube
- Name : SonarQube
- Server URL : http://localhost:9000/
- Server authentication token: [For this SonarQube> Administration> Security> Users> Tokens> create new token and copy ]
-
Add sonarqube scan in project
- Go to pipeline or Project > Configure > build
- Select Execute SonarQube Scanner
- Analysis properties (single module structure)
# unique project identifier (required) sonar.projectKey=[Project Key] # project metadata (used to be required, optional since SonarQube 6.1) sonar.projectName= [Project Name] sonar.projectVersion=1.0 # path to source directories (required) # path C:\Users\[User Name]\.jenkins\workspace\DemoProject (and not Git) which has source code sonar.sources=src sonar.java.binaries=target\\classes
- Analysis properties (multiple module structure)
sonar.projectKey=[Project Key] sonar.projectName= [Project Name] sonar.projectVersion=1.0 # nested module structure sonar.modules=module1,module2,moduleN sonar.projectBaseDir=. sonar.sources=src sonar.java.binaries=target\\classes # exclude TS files from scanning sonar.exclusions=**\\*.ts
- Report location: http://localhost:9000/dashboard/index/[Project Name]
- Add plugin
- Manage Jenkins> Manage Plugins> Available
- Search Cobertura Plugin and "Install without Restart"
- Add in project
- Select the project
- Go to 'Configure' > Build
- Select "Invoke top-level Maven targets"
- Maven Version: Maven [ maven name provided in earlier step]
- Goal: cobertura:cobertura
- Report location
- C:\Users\212393369.jenkins\workspace\DemoProject\target\site\cobertura