Bundling plugins with Hudson

If you'd like to ship plugins pre-installed in hudson.war, you can do so by placing your plugins inside hudson.war as /WEB-INF/plugins/*.hpi.

These files will be extracted whenever Hudson is started. This feature is new in Hudson 1.259.

Sample

Here is a maven pom to build a hudson webapp  bundled with your plugins

<dependencies>

		<dependency>
			<groupId>org.jvnet.hudson.main</groupId>
			<artifactId>hudson-war</artifactId>
			<version>${org.jvnet.hudson.version}</version>
			<type>war</type>
		</dependency>

	</dependencies>

	<build>
		<plugins>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<phase>generate-sources</phase>
						<goals>
							<goal>copy</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<artifactItems>
						<artifactItem>
							<groupId>${pom.groupId}</groupId>
							<artifactId>my_plugin1</artifactId>
							<version>${pom.version}</version>
							<type>hpi</type>
							<outputDirectory>${project.build.directory}/plugins</outputDirectory>
						</artifactItem>
						<artifactItem>
							<groupId>${pom.groupId}</groupId>
							<artifactId>my_plugin2</artifactId>
							<version>${pom.version}</version>
							<type>hpi</type>
							<outputDirectory>${project.build.directory}/plugins</outputDirectory>
						</artifactItem>
					</artifactItems>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<webResources>
						<resource>
							<directory>${project.build.directory}/plugins</directory>
							<targetPath>WEB-INF/plugins</targetPath>
						</resource>
					</webResources>
				</configuration>
			</plugin>


		</plugins>
	</build>

Here is an Ant target that bundles all the plugins in the ./plugins subdirectory into a new hudson.war file.

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="Hudson-Bundle">

    <property name="src.war" value="download/hudson.war" />
    <property name="dist" value="dist" />
    <property name="plugins.dir" value="plugins" />
    
    <target name="bundle" description="Merge plugins in ./plugins into a custom hudson.war">
        <mkdir dir="${dist}" />
        <zip destfile="${dist}/hudson.war">
            <zipfileset src="${src.war}" />
            <zipfileset dir="${plugins.dir}" prefix="WEB-INF/plugins" />
        </zip>
    </target>

    <target name="distclean">
        <delete dir="${dist}" />
    </target>

</project>

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
  1. Jun 08, 2010

    Saad says:

    This might also be due to my lack of understanding Maven, but how do you bundle ...

    This might also be due to my lack of understanding Maven, but how do you bundle jars with a plugin? For example, the Dimensions plugin requires 4 jars that also need to be in the classpath. These 4 jars are not included with the plugin because of licensing issues. I know where to include the .hpi.

    Thanks,
    Saad