Jenkins agent

    The first is a base image for Jenkins agents:

    • It pulls in both the required tools, headless Java, the Jenkins JNLP client, and the useful ones including git, tar, zip, and nss among others.

    • It establishes the JNLP agent as the entrypoint.

    • It includes the oc client tooling for invoking command line operations from within Jenkins jobs.

    • It provides Dockerfiles for both Red Hat Enterprise Linux (RHEL) and localdev images.

    Two more images that extend the base image are also provided:

    • Maven v3.5 image

    The Maven and Node.js Jenkins agent images provide Dockerfiles for the Universal Base Image (UBI) that you can reference when building new agent images. Also note the contrib and contrib/bin subdirectories. They allow for the insertion of configuration files and executable scripts for your image.

    The OKD Jenkins agent images are available on Quay.io or .

    Jenkins images are available through the Red Hat Registry:

    1. $ docker pull registry.redhat.io/openshift4/jenkins-agent-nodejs-10-rhel7:<v4.5.0>
    1. $ docker pull registry.redhat.io/openshift4/ose-jenkins-agent-maven:<v4.5.0>

    To use these images, you can either access them directly from Quay.io or ` or push them into your OKD container image registry.

    Each Jenkins agent container can be configured with the following environment variables.

    By default, the Jenkins JNLP agent JVM uses 50% of the container memory limit for its heap. This value can be modified by the CONTAINER_HEAP_PERCENT environment variable. It can also be capped at an upper limit or overridden entirely.

    By default, any other processes run in the Jenkins agent container, such as shell scripts or oc commands run from pipelines, cannot use more than the remaining 50% memory limit without provoking an OOM kill.

    By default, each further JVM process that runs in a Jenkins agent container uses up to 25% of the container memory limit for its heap. It might be necessary to tune this limit for many build workloads.

    Hosting Gradle builds in the Jenkins agent on OKD presents additional complications because in addition to the Jenkins JNLP agent and Gradle JVMs, Gradle spawns a third JVM to run tests if they are specified.

    The following settings are suggested as a starting point for running Gradle builds in a memory constrained Jenkins agent on OKD. You can modify these settings as required.

    • Ensure the long-lived Gradle daemon is disabled by adding org.gradle.daemon=false to the gradle.properties file.

    • Disable parallel build execution by ensuring org.gradle.parallel=true is not set in the gradle.properties file and that --parallel is not set as a command line argument.

    • To prevent Java compilations running out-of-process, set java { options.fork = false } in the build.gradle file.

    • Disable multiple additional test processes by ensuring test { maxParallelForks = 1 } is set in the file.

    • Override the Gradle JVM memory parameters by the GRADLE_OPTS, JAVA_OPTS or JAVA_TOOL_OPTIONS environment variables.

    • Set the maximum heap size and JVM arguments for any Gradle test JVM by defining the maxHeapSize and jvmArgs settings in build.gradle, or through the -Dorg.gradle.jvmargs command line argument.

    Jenkins agent pods, are deleted by default after the build completes or is stopped. This behavior can be changed by the Kubernetes plug-in pod retention setting. Pod retention can be set for all Jenkins builds, with overrides for each pod template. The following behaviors are supported:

    • Always keeps the build pod regardless of build result.

    • Default uses the plug-in value, which is the pod template only.

    • On Failure keeps the pod if it fails during the build.

    You can override pod retention in the pipeline Jenkinsfile:

    1. podTemplate(label: "mypod",
    2. cloud: "openshift",
    3. inheritFrom: "maven",
    4. podRetention: onFailure(), (1)
    5. containers: [
    6. ...
    7. ]) {
    8. node("mypod") {
    9. ...
    10. }