End-of-Life (EoL)
CloudBees Core pipeline on Kubernetes
CloudBees Core is the successor to CloudBees Jenkins Platform and CloudBees Jenkins Enterprise.
This article explains how to integrate the Prisma Cloud Jenkins plugin with a CloudBees Core build pipeline running in a Kubernetes cluster.
Key concepts
Refer to the article on setting up a Jenkins Pipeline in Kubernetes, as the core concepts are the same.
In the case of CloudBees Core on Kubernetes, much of the configuration is already done and the pipeline script is simpler because the JNLP Agent/Slave container is launched automatically.
The only tricky bit of configuration is determining the group ID (gid) of the docker group on your Kubernetes hosts, and using it to add some YAML to the default JNLP Agent/Slave pod configuration in CloudBees core.
This allows a pod running your pipeline to build and scan images using the mapped Docker socket of the underlying hosts.
Integrating Prisma Cloud
After installing the Prisma Cloud Jenkins plugin, configure the default pod template.
Prerequisites:
- You have set up a Kubernetes cluster using the Docker runtime and can SSH to nodes (see gid note below).
- You have installed Prisma Cloud Console. You can install Prisma Cloud inside or outside of the cluster, as long as any cluster node can reach Console over the network.
- You have installed CloudBees Core in your cluster. The CloudBees Core Install Guides are very helpful.
- You’ve built or identified an image for your Docker build executor that contains the docker binary. See an example Dockerfile below.
- Get the docker group ID (GID) used by the hosts in your Kubernetes cluster.
- SSH to a node in the cluster.
- Get the docker group GID. Copy it and set it aside for now.$ sudo grep docker /etc/group
- Log into the CloudBees Core console, and navigate to <CLOUDBEES_CONSOLE>/cjoc/view/All/.
- Click onkubernetes shared cloud.
- In the left navigation bar, click onConfigure.
- Scroll down to theKubernetes pod templatesection. You’ll notice a pod template named default-java with a single container named jnlp.
- Scroll to the bottom of the section. InRaw yaml for the Pod, enter the following snippet, replacing <GID> with the docker GID for your environment.spec: securityContext: fsGroup: <GID>Grant all containers in the pod access to the underlying host’s Docker socket (unless you do this manually in the pipeline script).
- Scroll up to theVolumessection.
- Add a Host Path Volume to the pod template.
- In bothHost pathandMount path, enter/var/run/docker.sock.
Add a second container to the pod template.In addition to the JNLP agent/slave, you’ll also want to spin up a container with the docker binary inside of it. Use the official docker image from DockerHub and name itbuild, although you could use any image with the docker client command installed in it. The docker client will use the Docker socket mounted from the underlying host.- Scroll up theContainer Templatesection.
- ClickAdd Container.
- InName, enterbuild.
- InDocker image, enterdocker.
- InWorking directory, enter/home/jenkins.
- InCommand to run, enter/bin/sh -c.
- InArguments to pass to the command, entercat.
- EnableAllocate pseudo-TTY.
Your CloudBees Core pod template config page should look like the folowing screenshot.
- 1— The first stage of the pipeline builds a new container image from a one-line Dockerfile inside the 'build' container specified in the pod config. Note that the twistlockScan and twistlockPublish functions cannot be run inside the container('<NAME>') block . They must be run in the default context.
- 2— The second stage runs the Prisma Cloud scanner on our newly built image in the default JNLP Agent/Slave container named 'jnlp'.
- 3— The third stage publishes the scan results to the Prisma Cloud Console.
Pipeline template
The following template can be used as a starting point for your own scripted pipeline.
This template illustrates how to build a new Docker image and then scan it with the Prisma Cloud scanner.
Because the pod template includes a container named 'build' that has the docker client command, you can use it in step (1) to build an image.
{ node { stage ('Build image') { // See 1 container('build') { sh """ mkdir myproj cd myproj echo 'FROM alpine:latest' > Dockerfile docker build -t myalpine:latest . """ } } stage ('Prisma Cloud scan') { // See 2 twistlockScan ca: '', cert: '', compliancePolicy: 'critical', dockerAddress: 'unix:///var/run/docker.sock', gracePeriodDays: 0, ignoreImageBuildTime: true, image: 'myalpine:latest', key: '', logLevel: 'true', policy: 'warn', requirePackageUpdate: false, timeout: 10 } stage ('Prisma Cloud publish') { See 3 twistlockPublish ca: '', cert: '', dockerAddress: 'unix:///var/run/docker.sock', ignoreImageBuildTime: true, image: 'myalpine:latest', key: '', logLevel: 'true', timeout: 10 } } }
This template has the following characteristics:
Most Popular
Recommended For You
Recommended Videos
Recommended videos not found.