-
Notifications
You must be signed in to change notification settings - Fork 38
FAQ
The most simple way is to create a Jenkinsfile in your git repo and create a multi-branch pipeline job in your Jenkins instance. See https://jenkins.io/doc/pipeline/tour/hello-world/ for more information. See below a simple Jenkinsfile. Note that the full list of available tools name can be found in the Tools (JDK, Maven, Ant) section.
pipeline {
agent any
tools {
maven 'apache-maven-latest'
jdk 'temurin-jdk17-latest'
}
options {
timeout(time: 30, unit: 'MINUTES')
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '5'))
}
stages {
stage('Build') {
steps {
sh '''
java -version
mvn -v
'''
}
}
}
post {
// send a mail on unsuccessful and fixed builds
unsuccessful { // means unstable || failure || aborted
emailext subject: 'Build $BUILD_STATUS $PROJECT_NAME #$BUILD_NUMBER!',
body: '''Check console output at $BUILD_URL to view the results.''',
recipientProviders: [culprits(), requestor()],
to: 'other.recipient@domain.org'
}
fixed { // back to normal
emailext subject: 'Build $BUILD_STATUS $PROJECT_NAME #$BUILD_NUMBER!',
body: '''Check console output at $BUILD_URL to view the results.''',
recipientProviders: [culprits(), requestor()],
to: 'other.recipient@domain.org'
}
}
}
- In general, you can use a pre-built/custom docker image and Jenkins pipelines, see https://wiki.eclipse.org/Jenkins#How_do_I_run_my_build_in_a_custom_container.3F.
- If your project requires UI test specific dependencies (e.g. metacity, mutter), you can try to use the
ubuntu-latest
pod template. The list of installed applications can be found here (it does not show all dependencies): https://github.com/eclipse-cbi/jiro-agents/blob/master/ubuntu/Dockerfile - If it does not work, use a pre-build/custom docker image.
For freestyle jobs, the label can be specified in the job configuration under "Restrict where this project can be run":
Example for pipeline jobs:
pipeline {
agent {
kubernetes {
label 'ubuntu-latest'
}
}
tools {
maven 'apache-maven-latest'
jdk 'temurin-jdk17-latest'
}
options {
timeout(time: 30, unit: 'MINUTES')
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '5'))
}
stages {
stage('Build') {
steps {
wrap([$class: 'Xvnc', takeScreenshot: false, useXauthority: true]) {
sh 'mvn clean verify'
}
}
}
}
post {
//...
}
}
pipeline {
agent {
kubernetes {
inheritFrom 'ubuntu-latest'
yaml """
spec:
containers:
- name: jnlp
resources:
limits:
memory: "4Gi"
cpu: "4000m"
requests:
memory: "4Gi"
cpu: "2000m"
"""
}
}
stages {
stage('Main') {
steps {
sh 'hostname'
}
}
}
}
You need to use a Jenkins pipeline to do so. Then you can specify a Kubernetes pod template. See an example below.
You can either use already existing "official" docker images, for example the maven:<version>-alpine
images or create your own custom docker image.
pipeline {
agent {
kubernetes {
label 'my-agent-pod'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:alpine
command:
- cat
tty: true
- name: php
image: php:7.2.10-alpine
command:
- cat
tty: true
- name: hugo
image: eclipsecbi/hugo:0.81.0
command:
- cat
tty: true
"""
}
}
stages {
stage('Run maven') {
steps {
container('maven') {
sh 'mvn -version'
}
container('php') {
sh 'php -version'
}
container('hugo') {
sh 'hugo -version'
}
}
}
}
}
See the Kubernetes Jenkins plugin for more documentation.
For security reasons, you cannot do that. We run an infrastructure open to the internet, which potentially runs stuff from non-trusted code (e.g., PR) so we need to follow a strict policy to protect the common good.
More specifically, we run containers using an arbitrarily assigned user ID (e.g. 1000100000) in our OpenShift cluster. The group ID is always root (0) though. The security context constraints we use for running projects' containers are "restricted". You cannot change this level from your podTemplate
.
Unfortunately, most images you can find on DockerHub (including official images) do not support running as an arbitrary user. Actually, most of them expect to run as root, which is definitely a bad practice.
OpenShift publishes guidelines with best practices about how to create Docker images. More specifically, see the section about how to support running with arbitrary user ID.
To test if an image is ready to be run with an arbitrarily assigned user ID, you can try to start it with the following command line:
$ docker run -it --rm -u $((1000100000 + RANDOM % 100000)):0 image/name:tag
You can use and integrate the Eclipse Foundation Jenkins shared library named: jenkins-pipeline-library.
This library proposes a containerBuild function for building docker images in the Eclipse Foundation infrastructure.
@Library('releng-pipeline') _
pipeline {
agent any
environment {
HOME = "${env.WORKSPACE}"
}
stages {
stage('build') {
agent {
kubernetes {
yaml loadOverridableResource(
libraryResource: 'org/eclipsefdn/container/agent.yml'
)
}
}
steps {
container('containertools') {
containerBuild(
credentialsId: '<jenkins-credential-id>',
name: 'docker.io/<namespace-name>/<container-name>',
version: 'latest'
)
}
}
}
}
}
You need to specify the tools
persistence volume.
pipeline {
agent {
kubernetes {
label 'my-agent-pod'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: custom-name
image: my-custom-image:latest
tty: true
command:
- cat
volumeMounts:
- name: tools
mountPath: /opt/tools
volumes:
- name: tools
persistentVolumeClaim:
claimName: tools-claim-jiro-<project_shortname>
"""
}
}
stages {
stage('Run maven') {
steps {
container('custom-name') {
sh '/opt/tools/apache-maven/latest/bin/mvn -version'
}
}
}
}
}
Important: Do not forget to replace <project_shortname>
in the claimName with your project name (e.g. tools-claim-jiro-cbi
for the CBI project).
Due to recent changes in the Jenkins Kubernetes plugin, you need to specify an empty dir volume for /home/jenkins
, if your build uses a directory like /home/jenkins/.ivy2
or /home/jenkins/.npm
.
pipeline {
agent {
kubernetes {
label 'my-agent-pod'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: custom-name
image: my-custom-image:latest
tty: true
command:
- cat
volumeMounts:
- mountPath: "/home/jenkins"
name: "jenkins-home"
readOnly: false
volumes:
- name: "jenkins-home"
emptyDir: {}
"""
}
}
stages {
stage('Run maven') {
steps {
container('custom-name') {
sh 'mkdir -p /home/jenkins/foobar'
}
}
}
}
}
Note: We are not satisfied with this workaround and are actively looking for a more convenient way to let projects use custom containers without specifying a bunch of volume mounts.