Jenkins plugin development

Why develop a jenkins plugin:

 

   Jenkins is a continuous integration operation and management platform ( same as hudson , you can check the wiki of jenkins for specific instructions ). Jenkins itself provides a management mechanism for plug-ins, which allow pluggable forms to exist. Although the jenkins plugin can provide many kinds of plugins, it still cannot meet the needs of our continuous integration, so we need to customize some plugins to support the operation of the entire continuous integration platform.

 

Jenkins run cycle:

     Jenkins has its own running lifecycle, as follows:

  • checkout - check out source code
  • Pre-build - precompile
    <developers>
        <developer>
          <id>xxx</id>
          <name>Developer gaofeng.qiangf</name>
          <email>[email protected]</email>
        </developer>
      </developers>
      <build>
        	<plugins>
          		<plugin>
            		<groupId>org.apache.maven.plugins</groupId>
            		<artifactId>maven-enforcer-plugin</artifactId>
            		<version>1.0.1</version>
            		<configuration>
               			<!-- your example configuration here -->
            		</configuration>
          		</plugin>
    			<plugin>
            		<groupId>org.apache.maven.plugins</groupId>
           			 <artifactId>maven-compiler-plugin</artifactId>
           				<configuration>
          		    		<source>1.6</source>
           			   		<target>1.6</target>
          	          		<debug>true</debug>
            		</configuration>
          			</plugin>
        	</plugins>
      	</build>
    
     
  • Build wrapper - environment to prepare builds, set environment variables, etc.
  • Builder runs - execute builds, such as calling Ant, Make , etc.
  • Recording - record output, such as test results
  • Notification - Notify members

Extension points provided by Jenkins :

In order to support the plug-in to run in each life cycle, jenkins provides various extension points, our main class must extend an extension point; for the current situation, basically only need to use Notifier and builder two extension points; the details are as follows:

  •   Builder : This extension point supports what needs to be done in this stage of construction, including steps such as prebuild postbuid , build environment, etc. For example, we replace the hosts plugin of the slave machine
  •  Notifier : Including notifications, message notifications, etc. Our sendnapolimessage is developed based on this extension point. Please refer to: https://wiki.jenkins-ci.org/display/JENKINS/Extension+points

Plug-in development steps

 

Settings settings.xml (including proxy)

 

  Because the plug-in uses the maven management form, the settings file is required. Students who understand maven should know the function of the settings file. I won't say much here. We need to add the following settings to our 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>

 Due to the slow download, I added a proxy with the following settings:

 

 

<!--Use proxy-->
  <proxy>
	<!-- Unique ID -->
      <id>my-proxy</id>
		<!-- Indicates whether the agent is activated. For example, if there are multiple agents mentioned above, the first activated agent will be found -->
      <active>true</active>
		<!-- Refers to using the http protocol to access -->
      <protocol>http</protocol>
		<!-- IP address of the server-->
      <host>218.14.227.197</host>
		<!-- Access port number-->
      <port>3128</port>
		<!-- If the server requires authentication, then you need to configure the username and password here-->
      <username>***</username>
      <password>***</password>
		<!-- Those domains specified here do not need to be proxied-->
      <nonProxyHosts>repository.mycom.com|*.google.com</nonProxyHosts>
    </proxy>

 setup maven3

 

 

Why does    Jenkins use maven3? There will be no problems when compiling with maven2, but when using the mvn - hpi plugin, a null pointer exception error will be reported. Check the wiki , this bug is not resolved, but switch to maven3 and the problem disappears , it should be that maven2 does not support this plugin well enough.

Create a maven project ( introduction to pom files)

 

1. Use the mvn –cpu create:hpi command. It will generate a hellobuilder example maven project by itself. , let you enter groupid and aid in the middle .

 

 2. Add the dependencies we need as well as jdk and developer maintenance instructions in maven. Same way as maven.

 

<developers>
    <developer>
      <id>xxxx</id>
      <name>Developer gaofeng.qiangf</name>
      <email>[email protected]</email>
    </developer>
  </developers>
  <build>
    	<plugins>
      		<plugin>
        		<groupId>org.apache.maven.plugins</groupId>
        		<artifactId>maven-enforcer-plugin</artifactId>
        		<version>1.0.1</version>
        		<configuration>
           			<!-- your example configuration here -->
        		</configuration>
      		</plugin>
			<plugin>
        		<groupId>org.apache.maven.plugins</groupId>
       			 <artifactId>maven-compiler-plugin</artifactId>
       				<configuration>
      		    		<source>1.6</source>
       			   		<target>1.6</target>
      	          		<debug>true</debug>
        		</configuration>
      			</plugin>
    	</plugins>
  	</build>

import eclipse

Use the command mvn eclipse:eclipse , and then use the import function to import in eclipse , this will not be introduced in detail, I believe everyone will use it

Project directory introduction (important):

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326824561&siteId=291194637