surefire results not showing in the test tab of gitlab CI/CD - java

I have a java-maven application and I am trying to display my junit results on gitlab as shown in the gitlab help here: https://docs.gitlab.com/ee/ci/junit_test_reports.html#viewing-junit-test-reports-on-gitlab
I added the maven-surefire-plugin in the pom build and the maven-surefire-report-plugin in the pom reporting section. I checked that it works because the surefire-report.html is correctly created in my local target repository, with the test results.
Then i configured my gitlabci.yaml by adding the last lines:
image: "maven"
before_script:
- cd gosecuri
stages:
- build
- test
- run
job_build:
stage: build
script:
- mvn compile
job_test:
stage: test
script:
- mvn package
artifacts:
paths:
- gosecuri/target/*.war
expire_in: 1 week
reports:
junit:
- target/surefire-reports/TEST-*.xml
The pipeline succeeds. In gitlab i have the message "There are no tests to show." in the job tests tab, and in the console I have this warning: target/surefire-reports/TEST-*.xml: no matching files
What am I missing? Thanks
PS: i'm running in gitlab.com Saas free plan

Right after docs you mentioned there is Enabling the feature paragraph.
This feature comes with the :junit_pipeline_view feature flag disabled
by default.
Looks like feature is disabled on public gitlab.com. If you launch your instance of GitLab you can enable it.
Update: Path to reports was incorrect: target/... should be gosecuri/target/...

Related

Skipping a step on CircleCI Orb build, version 2.1

I am using CircleCI CI/CD service. I have a basic build config for Java project with Gradle and Java 1.8. It works fine.
Here is the source of my .circleci/config.yml file
executors:
java1_8:
docker:
- image: 'cimg/openjdk:8.0'
orbs:
gradle: circleci/gradle#2.2.0
version: 2.1
workflows:
checkout-build-test:
jobs:
- gradle/test:
executor: java1_8
After completing the build CircleCI uploads artifacts and this is taking a lot of time.
I am looking for a way to skip the "Uploading Artifacts" step.
I can change to CircleCI version 2.0 if needed, but it would be nice to configure 2.1
I have found how to skip the step.
It turned out to be not very hard.
First, in gradle we can skip steps if we add a -x "step-to-skip" command-line parameters.
Second, CircleCi Gradle Orb can be configured with custom 'test' commands.
Here is the documentation: https://circleci.com/developer/orbs/orb/circleci/gradle#jobs-test
I have combined these two features to get a working configuration.
So, if I need to skip 'javaDoc' step, I would modify my CircleCi config.yml file in the following manner:
executors:
java1_8:
docker:
- image: 'cimg/openjdk:8.0'
orbs:
gradle: circleci/gradle#2.2.0
version: 2.1
workflows:
checkout-build-test:
jobs:
- gradle/test:
test_command: test -x javaDoc
executor: java1_8

How could my build passed, while it should not?

So I am learning about CI and pipelines and all that stuff and I just added my yaml file to my repository and it built successfully and tested successfully, but when I made a change in the code (I removed a semicolumn) it still said that the build was successful while it should say it had a error. I have no idea if my yaml file is not good, or what it is.
I am suspecting my yaml file is not as it should be but I did another post about it and I got no reaction.
My Yaml file:
My changed code:
Obviously, the code should error since there is no semicolumn anymore.
I build this project with gradle also and the yaml file there is:
build:
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew test
after_script:
- echo "End CI"
This code works like it should(on the other project) so I searched the maven version of that code, but could not find it.
Can anyone help me to confirm that the problem is in the yaml file and help me to what the yaml file should be (if that's the problem)?
Thanks!
Is the pipeline posted above your complete pipeline for your maven build? Your pipeline does nothing except echoing outputs.
If you need to build with maven you would need something like this:
image: maven:latest
stages:
- build
- test
build_a:
stage: build
script:
- mvn clean install -DskipTests --batch-mode --errors --fail-at-end --show-version
build_b:
stage: test
script:
- mvn test --batch-mode --errors --fail-at-end --show-version

Publish unit test results on GitHub for all matrix build versions

Currently, I'm trying to understand a (Java JUnit) test failure on a project, which only appears occasionally and on different JVM versions. To speed up examination of the failure, I am trying to get the test reports automatic on GitHub actions with a matrix build, but I did not find a way to do so.
I tried two plugins, action-surefire-report (https://github.com/ScaCap/action-surefire-report) and publish-unit-test-results (https://github.com/marketplace/actions/publish-unit-test-results).
With the action-surefire-report, I tried to set the name or other properties:
- name: Publish Test Report ${{ matrix.java }}
if: ${{ always() }}
uses: scacap/action-surefire-report#v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Unfortunately, no try resulted in publishing reports of more than one JVM.
For publish-unit-test-results, which contains an example of publishing python test results by downloading artifacts of the same build, I tried to copy this behavior:
publish-test-results:
name: "Publish Unit Tests Results"
needs: build
runs-on: ubuntu-latest
if: success() || failure()
steps:
- name: Download Artifacts
uses: actions/download-artifact#v2
with:
path: artifacts
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action#v1
with:
check_name: Unit Test Results
files: "target/surefire-reports/*.xml"
This fails, apparently since I cannot name the concrete xml-files of the test report.
The example code can be found on GitHub
Is it possible to get a test report for each JVM version of my current build? Since this is a pretty standard task to get test results for JUnit runs, I would have assumed that something like this is already implemented somewhere, and I am just not finding the documentation.

Run tests in Azure DevOps Build Pipeline

I would like to make a build pipeline in Azure DevOps including tests/code coverage.
For that, I created a very basic Java project:
package main:
- main class
- Calculator class
- add method
package test:
- CalculatorTest class
- addTest method
It's very basic, just for me to understand how test in pipeline work. I don't use maven or things like that. For the tests, I'm using JUnit framework.
In Azure DevOps pipeline, I imported my project from Github, and started to create the pipeline. I start from the starter template, which contains:
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
My question is:
What do I have to do to run my tests automatically ?
I've seen several examples on the Microsoft documentation but it was always for "complex" projects (like with maven etc.). And ass I'm new with Azure DevOps and YAML file/syntax, I'm lost.
I want to run my tests after each commit, and see the results (test + code coverage) in the pipeline summary, like it is described here : https://learn.microsoft.com/en-us/azure/devops/pipelines/test/review-continuous-test-results-after-build?view=azure-devops#view-test-results-in-build
Thanks a lot.
PS: For the moment I'm just focusing on tests but once it will be done I also would like to publish build artefacts. I would like the confirmation of that:
- task: PublishBuildArtifacts#1
Is that line correct ?
EDIT
The line - task: PublishBuildArtifacts#1 seems to work correclty but I have the following warning:
Directory '/home/vsts/work/1/a' is empty. Nothing will be added to build artifact 'drop'.
What does it mean ?
Finally I used the visual designer (like explained here: https://learn.microsoft.com/en-US/azure/iot-edge/how-to-ci-cd) and I added the Maven task.
I upgraded my project to use Maven, which is well integrated in Azure Devops.

How to solve Jenkins build error on recording test results?

After all the successful steps of my Jenkins build I get an error:
Recording test results
"ERROR: Publisher hudson.tasks.junit.JUnitResultArchiver aborted due to exception
hudson.AbortException: No test report files were found. Configuration error?"
I tried to search the answer in Jenkins documentation and on stack-overflow, however I didn't find any answer.
If you use behat3, then make sure that its version has junit formatter support, as it was missed in early versions https://github.com/Behat/Behat/pull/676
Also check that you have configured profile at behat.yml
behat 2
jenkins:
formatter:
name: pretty,junit
parameters:
output_path: ,build/logs/behat
behat 3
jenkins:
formatters:
junit: [build/log/behat]
Also build.xml must call it as "behat --profile jenkins"
I may assume that you have configured your test result path not to be related to Jenkins workspace (usually, this is the directory which you run tests from). JUnit result xml path should be configured in relation with Jenkins workspace directory, which is the root directory for you xml reports.

Categories

Resources