Skip to content

Instantly share code, notes, and snippets.

@brijesh-deb
Last active May 8, 2019 06:05
Show Gist options
  • Save brijesh-deb/14357a2253b34d318ee17296d65dfe3a to your computer and use it in GitHub Desktop.
Save brijesh-deb/14357a2253b34d318ee17296d65dfe3a to your computer and use it in GitHub Desktop.
#Jenkins

Jenkins setup

Install Jenkins

Configure global security

  • Manage Jenkins > Configure Global Security
  • Plugin Manage > check "Use browser for metadata download"

HTTP Proxy configuration

  • 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

Git setup

  • 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

Maven Setup

  • 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

SonarQube Setup

  • 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
    

Cobertura Setup

  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment