Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a way to build a Jenkins plugin using Ant. Let's make a script that builds a <a href="http://plugin-generator.jenkins-ci.org/" rel="nofollow">plugin skeleton</a> which name is "awesome".</p> <p><strong>Default plugin arborescence</strong></p> <pre><code>awesome-plugin/ -- awesome/ -- src/ -- pom.xml </code></pre> <p><strong>Instructions</strong></p> <ol> <li>Add a <code>lib/</code> folder which contains the following jars: <ul> <li>to be found in your Jenkins home directory <code>Jenkins\war\WEB-INF\lib</code> (<em>note</em>: you have to use the exact same versions that your current Jenkins use): <ul> <li>access-modifier-annotation-1.4.jar</li> <li>bridge-method-annotation-1.4.jar</li> <li>commons-io-1.4.jar</li> <li>guava-11.0.1.jar</li> <li>jenkins-core-1.513.jar</li> <li>json-lib-2.4-jenkins-1.jar</li> <li>remoting-2.23.jar</li> <li>sezpoz-1.9.jar</li> <li>stapler-1.207.jar</li> </ul></li> <li>to be found on the web (you can choose the last version released): <ul> <li><a href="http://www.mvnrepository.com/artifact/javax.servlet/servlet-api" rel="nofollow">servlet-api</a>-2.4.jar</li> </ul></li> </ul></li> <li>Replace the existing <code>pom.xml</code> with the following <code>build.xml</code>.</li> <li>In the Ant script, you should adapt: <ul> <li>the project name, <code>awesome</code> here,</li> <li>the plugin version,</li> <li>the Jenkins version this plugin is made for,</li> <li>the project group.id (main package), <code>org.jenkinsci.plugins.awesome</code> here.</li> </ul></li> </ol> <p><strong>New plugin arborescence</strong></p> <pre><code>awesome-plugin/ -- awesome/ -- src/ -- lib/ -- you should have 10 jars here -- build.xml </code></pre> <hr> <p><em>build.xml</em></p> <p></p> <pre><code>&lt;!-- Project dependent properties --&gt; &lt;property name="project_name" value="awesome"/&gt; &lt;property name="project_version" value="1.0"/&gt; &lt;property name="jenkins_version" value="1.513"/&gt; &lt;!-- which version of Jenkins is this plugin built against? --&gt; &lt;property name="project_groupid" value="org.jenkinsci.plugins.awesome"/&gt; &lt;!-- Build properties --&gt; &lt;property name="lib_dir" value="./lib"/&gt; &lt;property name="bin_dir" value="./bin" /&gt; &lt;property name="target_dir" value="./target"/&gt; &lt;property name="target_bin_dir" value="${target_dir}/${project_name}"/&gt; &lt;property name="plugin_targetMetaInf_dir" value="${target_bin_dir}/META-INF"/&gt; &lt;property name="plugin_targetWebInf_dir" value="${target_bin_dir}/WEB-INF"/&gt; &lt;property name="plugin_targetWebInfBin_dir" value="${plugin_targetWebInf_dir}/classes"/&gt; &lt;!-- Project paths --&gt; &lt;path id="project.source.path"&gt; &lt;pathelement path="src/main/java" /&gt; &lt;/path&gt; &lt;path id="project.class.path"&gt; &lt;fileset dir="${lib_dir}" includes="*.jar"/&gt; &lt;/path&gt; &lt;!-- Build flow --&gt; &lt;target name="build"&gt; &lt;antcall target="clean" /&gt; &lt;antcall target="compile" /&gt; &lt;antcall target="createTreeDirectory" /&gt; &lt;antcall target="copyBin"/&gt; &lt;condition property="has_file"&gt; &lt;and&gt; &lt;available file="${target_dir}/${project_name}.hpi" type="file"/&gt; &lt;/and&gt; &lt;/condition&gt; &lt;antcall target="createHpi"/&gt; &lt;condition property="has_dir"&gt; &lt;and&gt; &lt;available file="${target_bin_dir}" type="dir"/&gt; &lt;/and&gt; &lt;/condition&gt; &lt;antcall target="cleanTargetDirectory" /&gt; &lt;/target&gt; &lt;!-- Cleans existing binaries --&gt; &lt;target name="clean"&gt; &lt;delete includeEmptyDirs="true" quiet="true"&gt; &lt;fileset dir="${bin_dir}" /&gt; &lt;/delete&gt; &lt;mkdir dir="${bin_dir}"/&gt; &lt;/target&gt; &lt;!-- Compiles JAVA code --&gt; &lt;target name="compile"&gt; &lt;javac includeantruntime="false" destdir="${bin_dir}" debug="false" optimize="${optimize}" deprecation="${deprecation}" classpathref="project.class.path"&gt; &lt;src refid="project.source.path" /&gt; &lt;/javac&gt; &lt;/target&gt; &lt;!-- Creates necessary target folders --&gt; &lt;target name="createTreeDirectory" &gt; &lt;mkdir dir="${target_bin_dir}"/&gt; &lt;mkdir dir="${plugin_targetMetaInf_dir}"/&gt; &lt;mkdir dir="${plugin_targetWebInf_dir}"/&gt; &lt;mkdir dir="${plugin_targetWebInfBin_dir}"/&gt; &lt;/target&gt; &lt;!-- Moves new binaries to the plugin target --&gt; &lt;target name="copyBin"&gt; &lt;copy todir="${plugin_targetWebInfBin_dir}" &gt; &lt;fileset dir="${bin_dir}"/&gt; &lt;fileset dir="src/main/resources"/&gt; &lt;/copy&gt; &lt;/target&gt; &lt;!-- Cleans the target directory --&gt; &lt;target name="cleanTargetDirectory" if="has_dir"&gt; &lt;delete dir="${target_bin_dir}"/&gt; &lt;/target&gt; &lt;!-- Backup previous plugin --&gt; &lt;target name="saveOldHpiFile" if="has_file"&gt; &lt;move file="${target_dir}/${project_name}.hpi" tofile="${target_dir}/${project_name}.save.hpi"/&gt; &lt;/target&gt; &lt;!-- Archives the plugin --&gt; &lt;target name="createHpi"&gt; &lt;antcall target="saveOldHpiFile"/&gt; &lt;jar destfile="${target_dir}/${project_name}.hpi" basedir="${target_bin_dir}"&gt; &lt;manifest&gt; &lt;attribute name="Manifest-Version" value="{project_version}"/&gt; &lt;attribute name="Built-By" value="${user.name}"/&gt; &lt;attribute name="Created-By" value="${user.name}"/&gt; &lt;attribute name="Build-Jdk" value="${ant.java.version}"/&gt; &lt;attribute name="Extension-Name" value="${project_name}"/&gt; &lt;attribute name="Implementation-Title" value="${project_name}"/&gt; &lt;attribute name="Implementation-Version" value="${version}"/&gt; &lt;attribute name="Group-Id" value="${project_groupid}"/&gt; &lt;attribute name="Short-Name" value="${project_name}"/&gt; &lt;attribute name="Long-Name" value="${project_name}"/&gt; &lt;attribute name="Plugin-Version" value="${project_version}"/&gt; &lt;attribute name="Jenkins-Version" value="${jenkins_version}"/&gt; &lt;attribute name="Hudson-Version" value="${jenkins_version}"/&gt; &lt;/manifest&gt; &lt;/jar&gt; &lt;/target&gt; </code></pre> <p></p> <p>To launch the build, <code>cd</code> towards the <code>build.xml</code> and type <code>ant</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload