node {
try {
stage('Copy Project') {
sh '''
rm -rf DockerLoginTest
mkdir DockerLoginTest
cp pom.xml DockerLoginTest/
cp -r /Users/feyzaerdogan/Desktop/cypress/DockerJenkinsLoginTest/src DockerLoginTest/src
cd DockerLoginTest
'''
}
stage('Build') {
sh 'mvn clean install -U'
}
stage('Test') {
sh 'mvn test'
}
} finally {
// Bu kısım her zaman çalışır (post-always gibi)
junit 'target/surefire-reports/*.xml'
}
}
In a CI/CD project with Jenkins, the mvn clean install
and mvn clean test
commands in the terminal give successful results, but test records are not created in Jenkins. The target/surefire-plugins.xml
file is not created.
node {
try {
stage('Copy Project') {
sh '''
rm -rf DockerLoginTest
mkdir DockerLoginTest
cp pom.xml DockerLoginTest/
cp -r /Users/feyzaerdogan/Desktop/cypress/DockerJenkinsLoginTest/src DockerLoginTest/src
cd DockerLoginTest
'''
}
stage('Build') {
sh 'mvn clean install -U'
}
stage('Test') {
sh 'mvn test'
}
} finally {
// Bu kısım her zaman çalışır (post-always gibi)
junit 'target/surefire-reports/*.xml'
}
}
In a CI/CD project with Jenkins, the mvn clean install
and mvn clean test
commands in the terminal give successful results, but test records are not created in Jenkins. The target/surefire-plugins.xml
file is not created.
1 Answer
Reset to default 0Instead of try/finally blocks wrapped around the full code, I suggest adding post {always {}}
at the end, as well as some debug statements. This will at least allow you to see where your error is happening.
stages{
stage('Copy Project') {
sh '''
rm -rf DockerLoginTest
mkdir DockerLoginTest
cp pom.xml DockerLoginTest/
cp -r /Users/feyzaerdogan/Desktop/cypress/DockerJenkinsLoginTest/src DockerLoginTest/src
cd DockerLoginTest
'''
echo "Copy project stage completed"
}
stage('Build') {
sh 'mvn clean install -U'
echo "Build stage completed"
}
stage('Test') {
sh 'mvn test'
echo "See if file was created"
sh "ls target/surefire-reports"
echo "Test stage completed"
}
}
post {
always {
// Bu kısım her zaman çalışır (post-always gibi)
junit 'target/surefire-reports/*.xml'
}
}
try
/finally
without acatch
block. – imgnx Commented Mar 16 at 9:08try-catch-finally
in pipelines, it's hiding and masking the errors. Also, I'm not sure why are you expecting that file to be created - it's not where the reports are stored (I'm not even sure it's a standard file). Finally - can you confirm that Maven actually runs any tests, and you don't override the standard report directory? – Alexander Pletnev Commented Mar 16 at 21:06