Jenkins : Bundling plugins with Jenkins

This functionality has been removed in Jenkins 2.0. While you can still bundle plugins, the pinned plugins functionality has been removed, resulting in plugins that cannot be updated by users, as they will be overwritten on next startup.

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

These files will be extracted whenever Jenkins is started. This feature was added in 1.259.

There are several jars and plugins bundled in jenkins.war that way. The configuration usually goes to pom in war submodule of jenkins.

Sample

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

	<repositories>
		<repository>
			<id>jenkins</id>
			<url>http://maven.jenkins-ci.org/content/repositories/releases/</url>
		</repository>
	</repositories>
	<dependencies>
		<dependency>
			<groupId>org.jenkins-ci.main</groupId>
			<artifactId>jenkins-war</artifactId>
			<version>[1.560,)</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>
					<stripVersion>true</stripVersion>
					<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>
					<archive>
						<manifest>
							<mainClass>Main</mainClass>
						</manifest>
						<manifestEntries>
							<Jenkins-Version>${project.version}</Jenkins-Version>
						</manifestEntries>
					</archive>
					<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 jenkins.war file.

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

    <property name="src.war" value="download/jenkins.war" />
    <property name="dist" value="dist" />
    <property name="plugins.dir" value="plugins" />

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

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

</project>