Lại là 1 ngày đẹp trời mình run pipeline sau:
#!/usr/bin/env groovy podTemplate( cloud: 'kubernetes', containers: [], workspaceVolume: persistentVolumeClaimWorkspaceVolume( claimName: 'jenkins-controller', readOnly: false ), yaml: ''' kind: Pod spec: securityContext: runAsUser: 1000 runAsGroup: 1000 fsGroup: 1000 containers: - name: trivy image: aquasec/trivy:latest imagePullPolicy: IfNotPresent command: - cat tty: true resources: requests: cpu: 50m memory: 100Mi imagePullSecrets: - name: nimtechnology-gcr ''') { node(POD_LABEL) { ws("/home/jenkins/agent/workspace/"){ stage('Scan image with trivy') { container('trivy') { sh(script: '''#!/bin/sh -xe sleep 3s pwd ls -la ''') } } } } }


Chỗ này bạn vào config clouds -> kubernetes
workspaceVolume: persistentVolumeClaimWorkspaceVolume(
claimName: ‘jenkins-controller’,
readOnly: false
)
Giờ chúng ta làm sao để config workspaceVolume.
Đầu tiên bạn xem con jenkins controller đang được config với PVC nào?


Khi mà con jenkins-agent tạo ra file và folder thì nó cũng sẽ có trên con jenkins-controller

Nếu bạn gặp lỗi!!!!
Timed out waiting for websocket connection. You should increase the value of system property
Bạn có thể tham khảo link trên.
Bạn thực hiện update các plugin Kubernetes Client API and Kubernetes

Giờ run build lại:


reference links:
https://devopscube.com/jenkins-build-agents-kubernetes/
Bạn tham khảo link trên để có thêm các config hữu ích nhe!