Thursday, 24 October 2013

Plugin creation process in Jenkins


Jenkins is one open source tool to perform continuous integration. The basic functionality of Jenkins is to monitor a version control system and to start and monitor a build system (for example Apache Ant orMaven) if changes occur. Jenkins monitors the whole build process and provides reports and notifications to alert maintainers on success or errors.
Continuous integration is a process in which all development work is integrated at a predefined time or event and the resulting work is automatically tested and built. The idea is that development errors are identified very early in the process.                                
1. Installation
1.1 Installing Jenkins on Ubuntu   
Jenkins provides Debian/Ubuntu packages which install Jenkins and register Jenkins as start service. See the following URL for details. 
This installs a /etc/init.d/jenkins start script which starts Jenkins automatically at boot time.
If you start it locally, you find it running under the following URL: http://localhost:8080                       
For platforms you have native packages, see the Jenkins Homepage.
   
1.2 Installing Jenkins on windows
If you're running on Windows you might want to run Jenkins as a service so it starts up automatically without requiring a user to log in. The easiest way is follow Installing Jenkins as a Windows service. Alternatively, you can install a servlet container like Tomcat, which can run as a service by itself, and then deploy Jenkins to it.
   
2. Using the .war file of Jenkins
Download the jenkins.war file from Jenkins Homepage.
After download go to directory where Jenkins is download
then start Jenkins directly via the command line with java -jar jenkins*.war. If you start it locally, you find it running under the following URL: http://localhost:8080
To run it in your Tomcat server, put the .war file into the webapps directory. If you start Tomcat, your Jenkins installation will be available under http://localhost:8080/jenkins
             
3 .Apache Tomcat
If you want to install Jenkins in a web container, you can use for example Tomcat or Jetty. See for example the Apache Tomcat Tutorial
4 .Configure Jenkins 
4.1 Entering the JDK and your build system
Before using Jenkins you need to tell it where you’re JDK and maven installation is. Open Jenkins in your browser and click Manage Jenkins and then Configure System.                    
Enter the correct path to your JDK, Apache Ant and Maven and press the Save button below. Jenkins can also install these for your automatically.
      
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFad_WZdncjEL6Bk8ufGHa5iu7aYqvSmUEWWvKasBaDF7ZexXF5qhoO4ztjx9CwZYlCXf2UtrsdQjj4wi3TimBSS7dSzT-9MOKIcbKD8xhKd32Uw_w6zSR-DU76u8_0AZsIy7QkSMlhr20/s400/Untitled.png
5 .Setting Up Environment
To develop a plugin, you need Maven 3 and JDK 6.0 or later. If this is the first time you use Maven,  Maven download . It may be helpful to add the following to your ~/.m2/settings.xml (Windows users will find them in %USERPROFILE%\.m2\settings.xml):
<settings>
  <pluginGroups>
    <pluginGroup>org.jenkins-ci.tools</pluginGroup>
  </pluginGroups>
  <profiles>
    <!-- Give access to Jenkins plugins -->
    <profile>
      <id>jenkins</id>
      <activation>
        <activeByDefault>true</activeByDefault> <!-- change this to false, if you don't like to have it on per default -->
      </activation>
      <repositories>
        <repository>
          <id>repo.jenkins-ci.org</id>
          <url>http://repo.jenkins-ci.org/public/</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>repo.jenkins-ci.org</id>
          <url>http://repo.jenkins-ci.org/public/</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <mirrors>
    <mirror>
      <id>repo.jenkins-ci.org</id>
      <url>http://repo.jenkins-ci.org/public/</url>
      <mirrorOf>m.g.o-public</mirrorOf>
    </mirror>
  </mirrors>
</settings>
This will let you use short names for Jenkins Maven plugins (i.e. hpi:create instead of org.jenkins-ci.tools:maven-hpi-plugin:1.61:create),
though this is unnecessary once you are already working in a plugin project (only useful for initial hpi:create).
6 .Creating a New Plugin-
To start a new plugin or use an IDE (below).
Alternatively, if you are more comfortable with Maven, run the following command:
mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create
This will ask you a few questions, like the groupId (the Maven jargon for the package name) and the artifactId (the Maven jargon for your project name), then create a skeleton plugin from which you can start with. Make sure you can build this:
cd newly-created-directory
mvn package
Explanations:
-U means that Maven should update all relevant Maven plugins (check for plugin updates)hpi: this prefix specifies that the Jenkins HPI Plugin is being invoked, a plugin that supports development of Jenkins plugins
create is the goal which creates the directory layout and the POM for your new Jenkins plugin and it adds it to the module list
package is a standard phase which compiles all sources, runs the tests and creates a package - when used 
by the HPI plugin it will create an *.hpi file.
7.Building a Plugin-
To build a plugin, run mvn install.
This will create the file ./target/pluginname.hpi that you can deploy to Jenkins.
8.Setting up a productive environment with your IDE
Eclipse-:As Jenkins plugins are Maven projects,
Eclipse users have two ways to load a Jenkins plugin project. One is to use m2e, which tries to make Eclipse understand Maven "natively”, and the other is to use Maven Eclipse plugin, which makes Maven generate Eclipse project definitions. At the moment, unless you have some prior experience with m2e, we currently recommend plugin developers to go with the Maven Eclipse plugin.Eclipse users can run the following Maven command to generate Eclipse project  files run this cmd-
mvn -DdownloadSources=true -DoutputDirectory=target/eclipse-classes
eclipse:eclipse
Once this command completes successfully, use "Import..." (under the File menu in Eclipse) and select "General" > "Existing Projects into Workspace".
9.Debugging a Plugin –
 run the following command to launch Jenkins with your plugin: 
mvnDebug hpi: run
> set MAVEN_OPTS=-Xdebug -Xrunjdwp: transport=dt_socket,server=y,address=8000,
suspend=n
> mvn hpi: run
If you open http://localhost:8080/ in your browser, you should see the Jenkins page running in Jetty. 
The MAVEN_OPTS portion launches this whole thing with the debugger port 8000, so you should be able to start a debug session to this port from your IDE.
Once this starts running, keep it running. Jetty will pick up all the changes automatically. When you make changes to view files in src/main/resources or resource files in src/main/web app, just hit F5 in your browser to see the changes.
10. Changing Port in Jenkins
If you need to launch the Jenkins on a different port than 8080, set the port
through the system property jetty.port.
mvn hpi:run -Djetty.port=8090
How to install plugins-
Using the interface
Sometimes when you install, you will notice that the list of available plugins is empty.
If that is the case, from advanced tab on the Manage Plugins page, click on Check now
 (Button available in the bottom right of the page) to forcefully check for new updates. Once that is
done, you should see the list of plugins.
Deploying a custom build of a core plugin-
1. Stop Jenkins
2. Copy the custom HPI file to $JENKINS_HOME/plugins
3. Remove the previously expanded plugin directory
4. Start Jenkins. Or you can use By manual process ,given bellow.
By Manual
Save the downloaded *.hpi file into the$JENKINS_HOME/plugins directory. You will then need to
restart Jenkins (many containers let you do this without restarting the container.)
Caveat: names of the plugin directories on the download site are not always matching the name given to the plugin; common sense should apply.
Setting up a Jenkins job
The build of a project is handled via jobs in Jenkins. Select New Job " and select perfecto mobile test to create a new Job in Jenkins.  
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrxtd5Azy3Odhyphenhyphen1J_AlcauEidHf9OcETt1hYTuhNkKqa-7lCDwbotyUB3FhyphenhyphenlJ3HsP0H_Hfx_IMQokiNMQMC8KvrbBOQOUkre1qzCUFfD8XrZpsV_WoJkVSBe3aivHyqLp0kqgFzXH8vcF/s400/newJobp.png
Jenkins Backup and copying files
Jenkins stores all the settings, logs and build artifacts in its home directory, for example in /var/lib/jenkinsunder the default install location of Ubuntu.
To create a backup of your Jenkins setup, just copy this directory.
The jobs directory contains the individual jobs configured in the Jenkins install. You can move a job from one Jenkins installation to another by copying the corresponding job directory. You can also copy a job directory to clone a job or rename the directory.
Click reload config button in the Jenkins web user interface to force Jenkins to reload configuration from the disk.
See Adminstration of Jenkins for details.      
Thanking you !                
                       

Getting started with Elasticsearch and Node.js

  In this article we're going to look at using Node to connect to an Elasticsearch deployment, index some documents and perform a simple...