Writing your own custom plugin

Generate plugin skeleton and test the HelloWorldBuilder project.

  1. To generate the plugin skeleton, use:
    mvn hpi:create
    or
    mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create from the Jenkins Plugin tutorial
    You’ll be prompted to enter the groupId and artifactId, specify groupId (press enter to use default: org.jenkins-ci.plugins) and artifactId (name of the plugin)
  2. cd new-plugin-name
  3. mvn eclipse:eclipse
  4. mvn package
  5. mvn hpi:run (default port is 8080, but you can set your own with -Dport option (i.e. mvn hpi:run -Dport=9999, use this if port 8080 is in use – otherwise mvn hpi:run will fail)
  6. Open browser and enter URL “localhost:8080” (or 9999)
    You should see the page below. Click the link and that’ll take you to Jenkins home page
    Jenkins homepage link
  7. Click ‘Manage Jenkins’ > Configure System. Scroll down near the bottom of the page and you should see the Hello World Builder section
    Jenkins homepage link
  8. Navigate back to Jenkins home page and click New Item
  9. Give the project any name, select Freestyle Project, click OK.
  10. Scroll down to the Build section and click ‘Add build step’ > Say hello world
  11. Enter a name (i.e. TestName), save the project, then run a build (‘Build Now’)
  12. Click on the latest build under ‘Build History’ > Console Output.
    Jenkins homepage link

Maven Debug Jenkins Plugin in Eclipse

Attach debugger to Eclipse:

  1. Right click your Project
  2. Debug As > Debug Configurations
  3. Remote Java Application
  4. New. I name it a generic name like “Remote myapp”, you can change it to another Project by clicking Browse and selecting a Project. Or you can set up the debugger for each project if you wish.
  5. Close
  6. From the command line inside your project directory, type:
  7. mvnDebug -DJENKINS_HOME="C:\Program Files (x86)\Jenkins" -Dport=9090 hpi:run

  8. Go back to Eclipse (set your breakpoints) and press “ALT + SHIFT + D, D” to start debugging your project
  9. Once it says “Jenkins is up and fully running”, open a browser and type your Jenkins instance URL and port number, i.e. http://localhost:9090
  10. Click the link below

Handling two local instances of Jenkins

Use a separate folder for the second instance of Jenkins.

Temporarily set the $JENKINS_HOME environment variable to secondary Jenkins home directory, using -D (option to temporarily set an environment variable)

You can specify the directory:

-DJENKINS_HOME='C:\Program Files (x86)\Jenkins\secondInstance'

If you’re running a jar file from inside your second instance’s directory, you could just use ‘.’ to specify the current folder as JENKINS_HOME.

java -DJENKINS_HOME=. -jar jenkins.war

Jenkins will start the new instance and load all jobs and system configurations from here.