Files
homelab-jenkins-shared-libs/vars/homelabK8sAgent.groovy
duynguyen 22c8593d23 fix: use sonar-scanner-cli container instead of npx for sonar scan
npx sonar-scanner fails on node:18-slim — no Java. Switch to dedicated
sonarsource/sonar-scanner-cli container with Java + scanner bundled.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 15:25:49 +07:00

54 lines
1.3 KiB
Groovy

/**
* Returns a K8s pod YAML string for use in agent { kubernetes { yaml ... } }
*
* config keys (all optional):
* nodeImage - default: node:18-slim
* harborRegistry - default: harbor-core.harbor.svc.cluster.local
* withTools - include alpine/git container, default: false
* withSonar - include sonarsource/sonar-scanner-cli container, default: false
*/
def call(Map config = [:]) {
def nodeImage = config.nodeImage ?: 'node:18-slim'
def harborReg = config.harborRegistry ?: 'harbor-core.harbor.svc.cluster.local'
def withTools = config.withTools ?: false
def withSonar = config.withSonar ?: false
def toolsBlock = withTools ? """
- name: tools
image: alpine/git
command:
- sleep
args:
- infinity""" : ""
def sonarBlock = withSonar ? """
- name: sonar
image: sonarsource/sonar-scanner-cli:latest
command:
- sleep
args:
- infinity""" : ""
return """
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: ${nodeImage}
command:
- sleep
args:
- infinity
- name: docker
image: docker:dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
args:
- --insecure-registry=${harborReg}${toolsBlock}${sonarBlock}
""".stripIndent()
}