{product-title} provides a container image for running Jenkins. This image provides a Jenkins server instance, which can be used to set up a basic flow for continuous testing, integration, and delivery.
This image also includes a sample Jenkins job, which triggers a new build of a BuildConfig
defined in {product-title}, tests the output of that build, and then on successful build, retags the output to indicate the build is ready for production.
{product-title} follows the LTS releases of Jenkins.
This image comes in two flavors, depending on your needs:
-
RHEL 7
-
CentOS 7
RHEL 7 Based Image
The RHEL 7 image is available through Red Hat’s subscription registry:
$ docker pull registry.access.redhat.com/openshift3/jenkins-1-rhel7
CentOS 7 Based Image
This image is available on DockerHub. To download it:
$ docker pull openshift/jenkins-1-centos7
To use these images, you can either access them directly from these registries or push them into your {product-title} Docker registry. Additionally, you can create an ImageStream that points to the image, either in your Docker registry or at the external location. Your {product-title} resources can then reference the ImageStream. You can find example ImageStream definitions for all the provided {product-title} images.
You can manage Jenkins authentication in two ways:
-
{product-title} OAuth authentication provided by the OpenShift Login plug-in.
-
Standard authentication provided by Jenkins
OAuth
authentication is activated by configuring the Configure Global Security
panel in the Jenkins UI, or by setting the OPENSHIFT_ENABLE_OAUTH
environment variable on the Jenkins Deployment Config
to anything other than
false
. This activates the OpenShift Login plug-in, which retrieves the
configuration information from pod data or by interacting with the
{product-title} API server.
Valid credentials are controlled by your identity provider.
For example, if Allow All
is the default identity provider, you can provide
any non-empty string for both the user name and password.
For non-browser access, the OpenShift Login plug-in also supports using the HTTP bearer token authorization header to supply valid credentials for accessing Jenkins. Ensure to use the token associated with the serviceaccount for the project in which Jenkins is running, which, if you started Jenkins using the jenkins-ephemeral or jenkins-persistent templates, are found by using:
$ oc describe serviceaccount jenkins $ oc describe secret <serviceaccount secret name>
Valid users are automatically added to the Jenkins authorization matrix at log
in, where {product-title} Roles
dictate the specific Jenkins permissions the
user will have.
Users with the admin
role will have the traditional Jenkins administrative
user permissions. Users with the edit
or view
role will have progressively
less permissions. See the
Jenkins image source
repository README for the specifics on the OpenShift roles to Jenkins
permissions mappings.
Note
|
The |
Jenkins' users permissions can be changed after the users are initially established. The OpenShift Login plug-in polls the {product-title} API server for permissions and updates the permissions stored in Jenkins for each user with the permissions retrieved from {product-title}. If the Jenkins UI is used to update permissions for a Jenkins user, the permission changes are overwritten the next time the plug-in polls {product-title}.
You can control how often the polling occurs with the
OPENSHIFT_PERMISSIONS_POLL_INTERVAL
environment variable. The default polling
interval is five minutes.
-
Ensure you have installed the default imagestreams and templates.
-
Then create a new Jenkins application using:
-
Persistent volumes:
-
$ oc new-app jenkins-persistent
-
Or an EmptyDir type volume (where configuration does not persist across pod restarts):
$ oc new-app jenkins-ephemeral
Note
|
If you instantiate the template against releases prior to v3.4 of {product-title}, standard Jenkins authentication is used, and the default 'admin' account will exist with password 'password'. See Jenkins Standard Authentication for details about changing this password. |
Jenkins authentication is used by default if the image is run outside of {product-title}.
The first time Jenkins starts, the configuration is created along with the
administrator user and password. The default user credentials are admin
and
password
. Configure the default password by setting the JENKINS_PASSWORD
environment variable when using (and only when using) standard Jenkins
authentication.
To create a new Jenkins application using standard Jenkins authentication:
$ oc new-app -e \ JENKINS_PASSWORD=<password> \ openshift/jenkins-1-centos7
The Jenkins server can be configured with the following environment variables:
Variable name | Description |
---|---|
|
The password for the |
|
Determines whether the OpenShift Login plug-in manages authentication when logging into Jenkins. Enabled when set to any non-empty value other than "false". |
|
Specifies in seconds how often the OpenShift Login plug-in polls {product-title} for the permissions associated with each user defined in Jenkins. |
If you are going to run Jenkins somewhere other than as a deployment within your same project, you will need to provide an access token to Jenkins to access your project.
-
Identify the secret for the service account that has appropriate permissions to access the project Jenkins needs to access:
$ oc describe serviceaccount default Name: default Labels: <none> Secrets: { default-token-uyswp } { default-dockercfg-xcr3d } Tokens: default-token-izv1u default-token-uyswp
In this case the secret is named
default-token-uyswp
-
Retrieve the token from the secret:
$ oc describe secret <secret name from above> # e.g. default-token-izv1u Name: default-token-izv1u Labels: <none> Annotations: kubernetes.io/service-account.name=default,kubernetes.io/service-account.uid=32f5b661-2a8f-11e5-9528-3c970e3bf0b7 Type: kubernetes.io/service-account-token Data ==== ca.crt: 1066 bytes token: eyJhbGc..<content cut>....wRA
The token field contains the token value Jenkins needs to access the project.
Templates provide parameter fields to define all the environment variables (password) with predefined defaults. {product-title} provides templates to make creating a new Jenkins service easy. The Jenkins templates should have been registered in the default openshift project by your cluster administrator during the initial cluster setup.
The two available templates both define a deployment configuration and a service, but differ in their storage strategy, which affects whether or not the Jenkins content persists across a pod restart.
Note
|
A pod may be restarted when it is moved to another node, or when an update of the deployment configuration triggers a redeployment. |
-
jenkins-ephemeral
uses ephemeral storage. On pod restart, all data is lost. This template is useful for development or testing only. -
jenkins-persistent
uses a persistent volume store. Data survives a pod restart. To use a persistent volume store, the cluster administrator must define a persistent volume pool in the {product-title} deployment.
Once selected, you must instantiate the template to be able to use Jenkins.
To customize the official {product-title} Jenkins image, you have two options:
-
Use Docker layering.
-
Use the image as a Source-To-Image builder, described here.
You can use S2I to copy your custom Jenkins Jobs definitions, additional plug-ins or replace the provided config.xml file with your own, custom, configuration.
In order to include your modifications in the Jenkins image, you need to have a Git repository with the following directory structure:
- plugins
-
This directory contains those binary Jenkins plug-ins you want to copy into Jenkins.
- plugins.txt
-
This file lists the plug-ins you want to install:
pluginId:pluginVersion
- configuration/jobs
-
This directory contains the Jenkins job definitions.
- configuration/config.xml
-
This file contains your custom Jenkins configuration.
The contents of the configuration/ directory will be copied into the /var/lib/jenkins/ directory, so you can also include additional files, such as credentials.xml, there.
The following is an example build configuration that customizes the Jenkins image in {product-title}:
apiVersion: v1
kind: BuildConfig
metadata:
name: custom-jenkins-build
spec:
source: (1)
git:
uri: https://github.com/custom/repository
type: Git
strategy: (2)
sourceStrategy:
from:
kind: ImageStreamTag
name: jenkins:latest
namespace: openshift
type: Source
output: (3)
to:
kind: ImageStreamTag
name: custom-jenkins:latest
-
The
source
field defines the source Git repository with the layout described above. -
The
strategy
field defines the original Jenkins image to use as a source image for the build. -
The
output
field defines the resulting, customized Jenkins image you can use in deployment configuration instead of the official Jenkins image.
The official {product-title} Jenkins image includes the pre-installed Kubernetes plug-in that allows Jenkins slaves to be dynamically provisioned on multiple container hosts using Kubernetes and {product-title}.
To use the Kubernetes plug-in, {product-title} provides three images suitable for use as Jenkins slaves: the Base, Maven, and NodeJS images.
The first is a base image for Jenkins slaves:
-
It pulls in both the required tools (headless Java, the Jenkins JNLP client) and the useful ones (including git, tar, zip, nss among others).
-
It establishes the JNLP slave agent as the entrypoint.
-
It includes the oc client tooling for invoking command line operations from within Jenkins jobs, and
-
It provides Dockerfiles for both Centos and RHEL images.
Two additional images, that extends the base image are also provided, namely:
Both the Maven and NodeJS slave images are configured as Kubernetes Pod Tempate images within the {product-title} Jenkins image’s configuration for the Kubernetes plugin. That configuration includes labels for each of the images that can be applied to any of your Jenkins jobs under their "Restrict where this project can be run" setting. If the label is applied, execution of the given job will be done under an {product-title} Pod running the respective slave image.
The Maven and NodeJS Jenkins slave images provide Dockerfiles for both Centos and RHEL that you can reference when building new slave images.
Also note the contrib
and contrib/bin
subdirectories. They allow for the insertion of configuration files and executable
scripts for your image.
The Jenkins image also provides auto-discovery and auto-configuration
of slave images for the
Kubernetes plug-in. The Jenkins image searches for these in the existing image streams within the project that it is running in. The search specifically looks for image streams that have the label role
set to jenkins-slave
.
When it finds an image stream with this label, it generates the corresponding Kubernetes plug-in configuration so you can assign your Jenkins jobs to run in a pod running the container image provided by the image stream.
Note
|
This scanning is only performed once, when the Jenkins master is starting. Please restart the Jenkins master if you label additional image streams(to pickup the added labels). |
To use a container image as an Jenkins slave, the image must run the slave agent as an entrypoint. For more details about this, refer to the official Jenkins documentation.
For more details on the sample job included in this image, see this tutorial.
The Jenkins image’s list of pre-installed plug-ins includes a plug-in which assists in the creating of CI/CD workflows that run against an {product-title} server. A series of build steps, post-build actions, as well as SCM-style polling are provided which equate to administrative and operational actions on the {product-title} server and the API artifacts hosted there.
In addition to being accessible from the classic "freestyle" form of Jenkins job, the build steps as of version 1.0.14 of the {product-title} Pipeline Plug-in are also avaible to Jenkins Pipeline jobs via the DSL extension points provided by the Jenkins Pipeline Plug-in. The OpenShift Jenkins Pipeline build strategy sample illustrates how to use the OpenShift Pipeline plugin DSL versions of its steps.
The sample Jenkins job that is pre-configured in the Jenkins image utilizes the {product-title} pipeline plug-in and serves as an example of how to leverage the plug-in for creating CI/CD flows for {product-title} in Jenkins.
See the the plug-in’s README for a detailed description of what is available.