Set up the development environment

Task

Follow the instructions below to prepare your local development environment, alternatively run with Docker or choose the browser-based online IDE powered by GitPod.

Local Toolchain

For building and developing the Jenkins plugin Java SE Development Kit and Maven are required.

IDE

The preferred IDE for this workshop is IntelliJ IDEA Community Edition because it is free and Maven is shipped with the installation. Alternatively take the IDE of your choice (Eclipse, NetBeans, etc.) you are most familiar with.

JDK

Jenkins core is based on Java and therefore most of the Jenkins plugins also relies on Java or JVM compatible languages like Groovy. For this workshop we will use JDK 8 you can download for free from the Oracle website and install it afterwards. Ensure this JDK is properly configured in your IDE.

Maven

Most of the Jenkins plugins utilize Maven as the preferred build management system. The plugin to be changed is already configured as a Maven project providing a pom.xml.

Download Maven from related Apache project and extract it to an arbitrary path. Afterwards ensure the bin/ subdirectory is added to your PATH in order to invoke mvn from command line.

IDEA: Use the bundled Maven version or change it via Settings > Build Tools > Maven

In order to make Jenkins repositories available during Maven builds edit your ~/.m2/settings.xml (Windows: %USERPROFILE%\.m2\settings.xml) as follows:

<settings>
  <pluginGroups>
    <pluginGroup>org.jenkins-ci.tools</pluginGroup>
  </pluginGroups>

  <profiles>
    <!-- Give access to Jenkins plugins -->
    <profile>
      <id>jenkins</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>repo.jenkins-ci.org</id>
          <url>https://repo.jenkins-ci.org/public/</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>repo.jenkins-ci.org</id>
          <url>https://repo.jenkins-ci.org/public/</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <mirrors>
    <mirror>
      <id>repo.jenkins-ci.org</id>
      <url>https://repo.jenkins-ci.org/public/</url>
      <mirrorOf>m.g.o-public</mirrorOf>
    </mirror>
  </mirrors>
</settings>

Docker

For building and debugging the plugin inside a Docker container you can use following commands:

Build Plugin

docker run -it --rm -v "$PWD":/usr/src/app -v "$HOME"/.m2:/root/.m2 \
-w /usr/src/app maven:3-jdk-8-alpine mvn install

Run Debugging Instance

docker run -it -d --rm -p 8080:8080 -v "$PWD":/usr/src/app -v "$HOME"/.m2:/root/.m2 \
-w /usr/src/app maven:3-jdk-8-slim mvn hpi:run

GitPod

As an handy alternative without the need to install any tools locally you can use an one-click online IDE. GitPod provides a ready-to-code development environment in your browser.

Usage