Team,
my goal is to write from container that is spin using jenkinspipeline to the host file.
I have a use case where I am performing a test of code in one container main
and this generates a file in volume mounted emptydir
on both the containers as you will see the pod spec and then I want to run a scan on the code with that generated file as a parameter such that scan posts results to server with the code coverage results.
The unit-tests.sh creates a file myfile
under /coverage-data path in main from where scan container is to read.
I have two concerns
1 - my pipeline is failing with below syntax error.
2 - I did not test my logic yet due to 1 error above but am I on right track? like checking the condition COVERAGE_FILE
which is set by container main
if it generates file and writes on share emptydir?
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Only one agent type is allowed per agent section
agent {
^
: No agent type specified. Must be one of [any, kubernetes, label, none]
agent {
^
2 errors
ex: main
container to run code coverage then in sonar-scan
container pipeline runs a command to scan
jenkinsfile
pipeline {
agent {
label 'label-coverage-cli'
docker {
args '-v /:/hosts-root/'
}
}
environment {
COVERAGE_FILE = fileExists '/coverage-data/myfile'
}
stages {
stage('Code Coverage Tests') {
steps {
container('main') {
sh '''
unit-tests.sh
'''.stripIndent()
}
}
}
stage('Code Coverage Scan') {
when { expression { COVERAGE_FILE == 'true' } }
steps {
container('sonar-scan') {
sh '''
src/ui/scripts/ci/scan.sh
'''.stripIndent()
}
}
}
}
}
pod template for jenkins
apiVersion: v1
kind: Pod
spec:
imagePullSecrets:
- name: artifactory-build-project
volumes:
- name: shared-data
emptyDir: {}
containers:
- name: main
image: registry/tci-sonar-scanner:latest
resources:
requests:
memory: 32Gi
cpu: 18
limits:
memory: 48Gi
cpu: 24
volumeMounts:
- name: shared-data
mountPath: /coverage-data
command:
- /sbin/tini
args:
- --
- sleep
- infinity
- name: sonar-scanner
image: registry/sonarqube-scanner:4.7.0.2747
resources:
requests:
memory: 12Gi
cpu: 8
limits:
memory: 18Gi
cpu: 12
volumeMounts:
- name: shared-data
mountPath: /coverage-data
securityContext:
privileged: true
command:
- tail
args:
- "-f"
- "/dev/null"