Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 2. Jenkins agent
OpenShift Container Platform provides a base image for use as a Jenkins agent.
The Base image for Jenkins agents does the following:
-
Pulls in both the required tools, headless Java, the Jenkins JNLP client, and the useful ones, including ,
git,tar, andzip, among others.nss - Establishes the JNLP agent as the entry point.
-
Includes the client tool for invoking command-line operations from within Jenkins jobs.
oc -
Provides Dockerfiles for both Red Hat Enterprise Linux (RHEL) and images.
localdev
Use a version of the agent image that is appropriate for your OpenShift Container Platform release version. Embedding an
oc
The OpenShift Container Platform Jenkins image also defines the following sample
java-builder
The
java-builder
jnlp
java
java
mvn
2.1. Jenkins agent images Link kopierenLink in die Zwischenablage kopiert!
The OpenShift Container Platform Jenkins agent images are available on Quay.io or registry.redhat.io.
Jenkins images are available through the Red Hat Registry:
$ docker pull registry.redhat.io/ocp-tools-4/jenkins-rhel8:<image_tag>
$ docker pull registry.redhat.io/ocp-tools-4/jenkins-agent-base-rhel8:<image_tag>
To use these images, you can either access them directly from Quay.io or registry.redhat.io or push them into your OpenShift Container Platform container image registry.
2.2. Jenkins agent environment variables Link kopierenLink in die Zwischenablage kopiert!
Each Jenkins agent container can be configured with the following environment variables.
| Variable | Definition | Example values and settings |
|---|---|---|
|
| These values control the maximum heap size of the Jenkins JVM. If
By default, the maximum heap size of the Jenkins JVM is set to 50% of the container memory limit with no cap. |
|
|
| These values control the initial heap size of the Jenkins JVM. If
By default, the JVM sets the initial heap size. |
|
|
| If set, specifies an integer number of cores used for sizing numbers of internal JVM threads. | Example setting:
|
|
| Specifies options to apply to all JVMs running in this container. It is not recommended to override this value. | Default:
|
|
| Specifies Jenkins JVM garbage collection parameters. It is not recommended to override this value. | Default:
|
|
| Specifies additional options for the Jenkins JVM. These options are appended to all other options, including the Java options above, and can be used to override any of them, if necessary. Separate each additional option with a space and if any option contains space characters, escape them with a backslash. | Example settings:
|
|
| Specifies the version of Java version to use to run the agent in its container. The container base image has two versions of java installed:
| The default value is
Example setting:
|
2.3. Jenkins agent memory requirements Link kopierenLink in die Zwischenablage kopiert!
A JVM is used in all Jenkins agents to host the Jenkins JNLP agent as well as to run any Java applications such as
javac
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
By default, any other processes run in the Jenkins agent container, such as shell scripts or
oc
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.
2.4. Jenkins agent Gradle builds Link kopierenLink in die Zwischenablage kopiert!
Hosting Gradle builds in the Jenkins agent on OpenShift Container Platform 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 OpenShift Container Platform. You can modify these settings as required.
-
Ensure the long-lived Gradle daemon is disabled by adding to the
org.gradle.daemon=falsefile.gradle.properties -
Disable parallel build execution by ensuring is not set in the
org.gradle.parallel=truefile and thatgradle.propertiesis not set as a command-line argument.--parallel -
To prevent Java compilations running out-of-process, set in the
java { options.fork = false }file.build.gradle -
Disable multiple additional test processes by ensuring is set in the
test { maxParallelForks = 1 }file.build.gradle -
Override the Gradle JVM memory parameters by the ,
GRADLE_OPTSorJAVA_OPTSenvironment variables.JAVA_TOOL_OPTIONS -
Set the maximum heap size and JVM arguments for any Gradle test JVM by defining the and
maxHeapSizesettings injvmArgs, or through thebuild.gradlecommand-line argument.-Dorg.gradle.jvmargs
2.5. Jenkins agent pod retention Link kopierenLink in die Zwischenablage kopiert!
Jenkins agent pods, are deleted by default after the build completes or is stopped. This behavior can be changed by the Kubernetes plugin pod retention setting. Pod retention can be set for all Jenkins builds, with overrides for each pod template. The following behaviors are supported:
-
keeps the build pod regardless of build result.
Always -
uses the plugin value, which is the pod template only.
Default -
always deletes the pod.
Never -
keeps the pod if it fails during the build.
On Failure
You can override pod retention in the pipeline Jenkinsfile:
podTemplate(label: "mypod",
cloud: "openshift",
inheritFrom: "maven",
podRetention: onFailure(),
containers: [
...
]) {
node("mypod") {
...
}
}
- 1
- Allowed values for
podRetentionarenever(),onFailure(),always(), anddefault().
Pods that are kept might continue to run and count against resource quotas.