I have a project that does the building, testing and deployment process in Dockerfiles, and I want to apply a jenkins pipeline to it. I want to keep the jenkins-part as simple, slim and agnostic as possible. Installing additional plugins to jenkins is possible. Modification to the dockerfiles are possible.
For example consider this Jenkinsfile
pipeline {
agent { label 'my_agent' }
stages {
stage("TestInDocker") {
steps {
sh "docker build --target tester -t my_tester ."
sh "docker run -v $PWD/coverage:/workdir/coverage my_tester"
}
}
}
post {
always {
sh "ls -la $PWD/coverage/junit"
junit '$PWD/coverage/junit/*.xml'
}
}
}
in this example the post-block creates the following output
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] sh
+ ls -la /srv/jenkins/coverage/junit
total 360
drwxr-xr-x 2 root root 4096 Jul 22 11:56 .
drwxr-xr-x 5 root root 4096 Jul 22 11:56 ..
-rw-r--r-- 1 root root 357595 Jul 22 15:23 TESTS-HeadlessChrome_73.0.3683_(Linux_0.0.0).xml
[Pipeline] junit
Recording test results
No test report files were found. Configuration error?
Error when executing always post condition:
Also: [... java stack trace from junit ...]
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
In this example the required file seems to get created, but the junit-plugin can't seem to find it. How would I modify this example so that the junit-plugin can find the test report files?
additional notes/background:
- the output seems to be created successfully, but they belong to root instead of the jenkins user. Could that be the reason why junit can't see them?
- in my specific case, there are some failing tests, but I don't think they are the root of the problem
- the report-file is created with karma-junit-reporter inside the dockercontainer
- I am new to jenkins, so I guess I could be doing something wrong on a fundamental level
- I guess using the docker-plugin for jenkins would work, though I still would have to get the junit artifacts out of the container and pass it to the Jenkins JUnit Plugin. Answers using the docker-plugin are welcome.
- my tests inside the dockerfile are karma/angular tests and require a chromium-installation on the runner. If it turns out that doing this in docker is too annoying, than I will probably install chromium on all agents, and use the nodejs-plugin for jenkins. But for now I am still investigating different options