Jenkins Plugin Development

Jenkins Plugin Development

Maven settings file

Depending in your present working system, you will have to create/edit the .m2/settings.xml file. Windows customers will discover the settings.xml file by issuing the next command in Command Prompt:

echo %USERPROFILE%.m2settings.xml

Mac working system customers can edit/create the settings.xml file in ~/.m2/settings.xml.

Note that the settings factor within the settings.xml file comprises parts used to outline values that configure Maven execution in numerous methods, akin to pom.xml. However, these shouldn’t be bundled to any particular venture or distributed to an viewers, as they embody values such because the native repository location, alternate distant repository servers, and authentication info.

Place the next content material into the settings.xml file:

HelloWorld Jenkins plugin

In order to create a Jenkins plugin, you will have to make use of Maven archetypes, which you’ll be able to examine  at Issue the next command so as to generate a Jenkins Hello World plugin:

mvn archetype:generate -Dfilter=io.jenkins.archetypes:hello-world

Here is a pattern operating session:

Notice right here that is entered for the archetype, a plugin model of 4 is chosen, and a price of jenkins-helloworld-example-plugin is outlined. Hit Enter for the default values:

If all goes efficiently, it’s best to get the output of BUILD SUCCESS in Command Prompt.

You have to just remember to can construct your Jenkins plugin, so ensure to run the next command in Command Prompt:

// First go into the newly created listing
cd jenkins-helloword-example-plugin
// Then run the maven construct command
mvn bundle

The mvn bundle command will create a goal listing and run any assessments that you’ve created within the listing:

As you possibly can see, the Jenkins archetype really created some assessments for the Hello World Jenkins plugin instance.

Folder structure rationalization

The following is a screenshot of the newly created jenkins-helloworld-example-plugin listing:

The src listing comprises the supply recordsdata for the Jenkins plugin in addition to assessments for the plugins.

The goal listing is generated with the mvn bundle. There can also be a pom.xml file, which Maven created once you ran the archetype sub-command.

A Project Object Model (POM) is the elemental unit of labor in Maven. It is an XML file that comprises details about the venture and configuration particulars utilized by Maven to construct the venture. It comprises default values for many initiatives. Examples for this embody the construct listing, which is goal, the supply listing, which is src/predominant/java, and the check supply listing, which is src/check/java.

Jenkins plugin supply code rationalization

As talked about earlier, the src listing comprises the supply recordsdata for the Jenkins plugin. Notice that Maven created a moderately lengthy listing construction, which is widespread, and, as such, the listing construction for the helloworld plugin is ./src/predominant/java/io/jenkins/plugins/pattern/ The check file itself is in ./src/check/java/io/jenkins/plugins/pattern/

Here’s the supply code for the class right here:

bundle io.jenkins.plugins.pattern;

import hudson.Launcher;
/* More Import Statements Here */

public class HelloWorldBuilder extends Builder implements SimpleBuildStep {

    /* Rest of strategies in Github Source */

    public void carry out(Run run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
       if (useFrench) {
            listener.getLogger().println("Bonjour, " + title + "!");
        } else {
            listener.getLogger().println("Hello, " + title + "!");
    public static closing class DescriptorImpl extends BuildStepDescriptor {
        /* Rest of the supply in Github */

Notice that the HelloWorldBuilder class extends the Builder class, which is a Jenkins core class. Also discover that you simply’re utilizing a category known as BuildStepDescriptor, which can also be a Jenkins class. The supply code for this file might be seen within the GitHub repository known as jenkins-plugin-example in ( file.

For the check instances in,  use JUnit, which is a well-liked unit testing library for the Java programming language:

bundle io.jenkins.plugins.pattern;
import hudson.mannequin.FreeStyleBuild;
/* More Import Statements Here */
public class HelloWorldBuilderTest {
public JenkinsRule jenkins = new JenkinsRule();
    closing String title = "Bobby";
public void testConfigRoundtrip() throws Exception {
        FreeStyleProject venture = jenkins.createFreeStyleProject();
venture.getBuildersList().add(new HelloWorldBuilder(title));
venture = jenkins.configRoundtrip(venture);
jenkins.assertEqualDataBoundBeans(new HelloWorldBuilder(title), venture.getBuildersList().get(0));
    /* More check Cases on this file. */

The above Java check file has annotations akin to @Rule@Override@Test, and @DataBoundSetter, which are a type of metadata offering knowledge a few program that isn’t a part of this system itself. Annotations don’t have any direct impact on the operation of the code they annotate. You can discover the supply code for this file within the GitHub repository known as jenkins-plugin-example within the file ( ).

Building a Jenkins plugin

In order to construct a Jenkins plugin, you have to run the mvn set up command within the plugin listing.

The mvn set up command will each construct and check the Jenkins plugin and, extra importantly, create a file known as pluginname.hpi. In this case, it is going to create a file known as jenkins-helloworld-example-plugin.hpi within the goal listing that you need to use to deploy to Jenkins.

Here’s a pattern set up run:

Installing a Jenkins plugin

Now, so as to set up a newly constructed and put in HelloWorld instance plugin, you’ll have to go to the Jenkins Dashboard Manage Jenkins | Manage Plugins view after which click on the Advanced tab. You may instantly go to the plugin part by going to scheme://area/pluginManager. Alternately, should you’re operating Jenkins domestically, simply go to http://localhost:8080/pluginManager/.

Then guarantee to click on the Advanced tab or go to http://localhost:8080/pluginManager/superior:

You’ll then have to go to the Upload Plugin part:

Click Choose File after which discover the newly created Helloworld Jenkins plugin, which must be within the listing:


Then click on the Upload button.

The following is a screenshot of the newly put in Helloworld instance plugin:

Guest Author— Jean-Marcel Belmont

Jean-Marcel Belmont is the creator of Hands-On Continuous Integration and Delivery.

Read Original – Click Here


Leave a reply

Your email address will not be published. Required fields are marked *


©2018 US - Hosting Network

Log in with your credentials

Forgot your details?