Jenkins Kubernetes Plugin Security Context

10/28/2018

How I can change securityContext of my pods in Jenkins Kubernetes Plugin. For example, run docker in docker images with privileged mode in docker environment.

-- ColossusMark1
docker
jenkins
kubernetes

1 Answer

10/29/2018

I believe this should work (as per the docs):

def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label, yaml: """
apiVersion: v1
kind: Pod
metadata:
  labels:
    some-label: some-label-value
spec:
  containers:
  - name: busybox
    image: busybox
    command:
    - cat
    tty: true
    securityContext:
      allowPrivilegeEscalation: true
"""
) {
    node (label) {
      container('busybox') {
        sh "hostname"
      }
    }
}
-- Rico
Source: StackOverflow