Skip to content

Instantly share code, notes, and snippets.

@peterwwillis
Last active February 14, 2020 05:02
Show Gist options
  • Save peterwwillis/665889aff95db6d70071f0ce0cc26653 to your computer and use it in GitHub Desktop.
Save peterwwillis/665889aff95db6d70071f0ce0cc26653 to your computer and use it in GitHub Desktop.
Docker cheat sheet

Run commands

Use Docker to build a Jenkins plugin

  1. Check out a Jenkins plugin from GitHub
    $ git clone [email protected]:jenkinsci/configuration-as-code-secret-ssm-plugin.git
    $ cd configuration-as-code-secret-ssm-plugin
  2. Build the plugin. Change the maven tag to something like 3-jdk-8 or 3-jdk-11 if you run into errors, as some plugins only build with one JDK version.
    • Run as a non-root user
      docker run --rm -it \
          -u 1000 \
          -v ~/.m2:/var/maven/.m2 \
          -v "$(pwd)":/usr/src/mymaven \
          -w /usr/src/mymaven \
          -e MAVEN_CONFIG=/var/maven/.m2 \
          maven:3-jdk-8 \
          mvn -Duser.home=/var/maven clean install
    • If that doesn't work due to more permissions issues, create a volume just for your maven repository and stick to root
      $ docker volume create --name maven-repo
      # Copy your existing repo into the volume
      $ docker run --rm -it \
          -v maven-repo:/root/.m2 \
          -v ~/.m2:/user/.m2 \
          maven:3-jdk-8 \
          /bin/bash -c "cp -r /user/.m2/* /root/.m2/"
      # Run maven as root
      $ docker run --rm -it \
          -v maven-repo:/root/.m2 \
          -v "`pwd`":/usr/src/mymaven \
          -w /usr/src/mymaven \
          maven:3-jdk-8 \
          mvn clean install
  3. Use the compiled .hpi file
    $ ls target/*.hpi
    target/configuration-as-code-secret-ssm.hpi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment