My favorites | Sign in
Project Home Wiki Issues Source
Search
for
QuickReferenceJenkins  
Getting going with Jenkins
Updated Apr 8, 2012 by mobile.h...@gmail.com

Adding a projects to Jenkins

Preparing a project for Jenkins

pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>   <groupId>simple-code-patterns</groupId>   <artifactId>java_patterns</artifactId>   <version>0.0.1</version>   <packaging>pom</packaging>   <name>java_patterns</name>   <build>     <sourceDirectory>src</sourceDirectory>     <outputDirectory>build/classes</outputDirectory>   </build>   <properties>     <sonar.language>java</sonar.language>
     <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
     <sonar.surefire.reportsPath>test-reports</sonar.surefire.reportsPath>
     <sonar.cobertura.reportPath>test-reports/coverage.xml</sonar.cobertura.reportPath>
   </properties>   <ciManagement>     <system>Hudson</system>     <url>http://localhost:8080/job/java_patterns/</url>   </ciManagement> </project> 

mvnSonar.sh

 #/usr/bin/bash
 

# Purpose: Manually test the Maven to Sonar interface.

#cd .. # build the code. ant sonar

# Load the data to Sonar mvn -f pom.xml -e -B sonar:sonar -Dsonar.jdbc.driver=com.mysql.jdbc.Driver -Dsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

# Clean up after maven run. rm -rf target

# clean up after ant ant clean

Adding a single/simple build to jenkins

  1. create a pom.xml
  2. Goto the Jenkins server home page.
  3. click 'New Job'
    1. fill in name
    2. Select 'Build a free-style software project'
    3. Click Ok, at the bottom.
  4. Fill in description
  5. Select the 'Source Code Management'
  6. set Build Triggers
    • E.g: time trigger: '0 5 ' Builds every day at five in the morning.
  7. Click 'Add build steps'
    • select 'Execute shell' for a std Makefile set-up.
    • cd c_patterns; make sonar
  8. Go to 'Post-build Actions'
    • Sonar:
  9. Click 'Save'

Installation

  1. sudo apt-get install jenkins
  2. sudo apt-get install maven2
    • Needed for interfacing with sonar.
  3. go get the plugins.

Creating a project

Integrating with sonar

See: http://docs.codehaus.org/display/SONAR/Hudson+and+Jenkins+Plugin

On Jenkins

  1. Select: Manage Jenkins -> Manage Plugins
  2. Select the 'Available' plugin.
  3. Search for 'Sonar plugin'
  4. Select it
  5. Scroll to the bottom and click 'Install'
  6. Click the 'Restart Jenkins' button.
  7. Select 'Manage Jenkins' -> 'Configure System'
  8. In the sonar section click Add Sonar.
  9. Fill out the fields:
    • Name: SonarServer
    • Database URL: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
      • This can be found under 'sonar.jdbc.url:' in the sonar 'conf/sonar.properties'
    • Database login: sonar
      • sonar.jdbc.username:
    • Database driver: com.mysql.jdbc.Driver
      • under sonar.jdbc.driverClassName:
    • Got to the bottom and click 'Save'
    • For each project
    1. Go to theproject
    2. Select configure
    3. Check of sonar
    4. fill out fields
    5. Click save

On Sonar

  1. download | Build stability
  2. copy it extensions/plugin
  3. restart sonar.
  4. Also remember to login and add the widget to the dashoard
  5. Add ciManager to each projects pom.xml file.

 <ciManagement>   <system>Hudson</system>   <url>http://hudson.glassfish.org/job/hudson/</url> </ciManagement> 

Extensions

Troubleshooting

version control errors

Git problem

FATAL: Could not apply tag jenkins-AgileTest-5

See: http://stackoverflow.com/questions/2671296/hudsongit-fatal-could-not-apply-tag

Fix:

  1. In the browser go to: jenkins -> Manage Jenkins -> Configure System
  2. Scroll down to 'Git plugin'
  3. insert the values
    • e.g: jenkins / jenkins@localhost

build errors

ant

FATAL: Unable to find build script at

See: http://jenkins.361315.n4.nabble.com/Problem-with-location-of-ANT-build-xml-file-td3425697.html

Fix:

  1. Select 'configure' on the project page.
  2. go to 'Build'
  3. Click 'Advanced'
  4. In the 'Build file' field write : 'AgileTest/build.xml'
    • relative path to build.xml from the root of the git project.
    • 'workspace' has nothing to do with Eclipse.
  5. click 'Save'

The 'build.xml' is actually in the root of agile."

 FATAL: Unable to find build script at /var/lib/jenkins/jobs/AgileTest/workspace/build.xml
 

Plugin issues

Sonar plugin

Sonar plugin doesn't become available

even though it claims to be succesfully installed prior to reboot.

Upgrading to Jenkins ver. 1.424.3 fixed the issue.

Ubuntu: 11.10 Jenkins: Jenkins ver. 1.409.1 Sonar plugin: 1.8

(doesn't work):
  1. download the plugin manually from: http://updates.jenkins-ci.org/download/plugins/sonar/
  2. cp ~/Downloads/sonar.hpi /tmp
  3. sudo -s -H -u jenkins
  4. cd /var/lib/jenkins/plugins

Cannot execute mojo: sonar. It requires a project with an existing pom.xml, but the build is not using one

Create a small pom.xml in the root of the project. See: http://docs.codehaus.org/display/SONAR/Groovy+Plugin

and: http://leanjavaengineering.wordpress.com/2011/07/29/grails-hudson-jenkins-part-6-sonar/

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>my.group.id</groupId>
  <artifactId>arifactId</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <name>The Name of My Project</name>
  <build>
    <sourceDirectory>src/main/groovy</sourceDirectory>
  </build>
  <properties>
    <sonar.language>grvy</sonar.language>
    <sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
  </properties>
</project>

Sonar integration

source statistics is not shown

Fix: Make sure sourceDirector is the correct relative path(in pom.xml).

I ended up with the path relative to the project I was testing, not the Git structure.

  • Correct: <sourceDirectory>src</sourceDirectory>
  • Wrong: <sourceDirectory>AgileTest/src</sourceDirectory>

Can not execute Sonar

Added a new C project and the build failed.

Fix: change the language from 'C' (upper case C) to 'c' (lower case c).

In the project configuration under 'Sonar' 'Advanced button under the 'Language' field.

org.apache.maven.lifecycle.LifecycleExecutionException: Can not execute Sonar
...
Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute Sonar
...
Caused by: java.lang.RuntimeException: Quality profile not found for Automatedliving:AgileTestC, language C
...
Comment by henryp...@gmail.com, Apr 19, 2012

Adding support for multiple source directories:

<plugin>
<groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions>
<execution>
<id>add-source</id> <phase>generate-sources</phase> <goals>
<goal>add-source</goal>
</goals> <configuration>
<sources>
<source>Common</source> <source>FileOps?</source> <source>GetData?</source> <source>Statistics</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

and in <properties>...</> add:

<sonar.phase>generate-sources</sonar.phase>

Sign in to add a comment
Powered by Google Project Hosting