Gitlab CI/CD Pipeline generates error "no matching files. Ensure that the artifact path is relative to the working directory"
Asked Answered
T

1

7

I am a beginner and this is the first time I am building a CI/CD pipeline for my maven java selenium project and trying to run the pipeline locally by installing a runner in my local machine. Everytime I run my pipeline I recieve an error stating that"WARNING: gosecuri/target/surefire-reports/TEST-*.xml: no matching files. Ensure that the artifact path is relative to the working directory (C:\GitLab-Runner\builds\CXWJTzxhV\0\ssc-onyx-qa\ssc-onyx-test-automation) ERROR: No files to upload" Please can someone help me

Pipeline code is mentioned below:-

stages:
  - test
image: "maven:3.8.7"
variables:
  MAVEN_OPTS: >-
    -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
    -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"
cache:
  paths:
    - .m2/repository/
    - target/
test-job:
  stage: test
  services:
    - selenium/standalone-chrome
  script:
    - echo "Compiling the code..."
    - mvn --version
    - mvn "$MAVEN_CLI_OPTS" clean test -Dhost=selenium__standalone-chrome
    - Get-Command zip
  artifacts:
    when: always
    paths:
      - target/
    reports:
      junit:
        - gosecuri/target/surefire-reports/TEST-*.xml
Thomism answered 8/2 at 4:22 Comment(0)
G
1

You are directing Gitlab to look for xml files in this directory: gosecuri/target/surefire-reports/TEST-*.xml at the end of your pipeline file here:

reports:
      junit:
        - gosecuri/target/surefire-reports/TEST-*.xml

Gitlab is telling you that its working directory is C:\GitLab-Runner\builds\CXWJTzxhV\0\ssc-onyx-qa\ssc-onyx-test-automation. Those are completely different paths, so the Runner cannot find the files that you are pointing it to.

The Gitlab-Runner is operating in a different working directory than the one you are working in. It has access to your files, and is able to determine which file you're pointing it to if you use relative filepaths. This would be more intuitive if you were running the Pipeline on gitlab.com, as it is more clear that they are using an isolated environment that is not the same as your computer, but you can imagine it as being the same situation for a local Runner too. The Runner uses an isolated environment on your computer with access to your files at Gitlab.

If you insist on using a hard-coded path, you can make it relative to C:\GitLab-Runner\builds\CXWJTzxhV\0\ssc-onyx-qa\ssc-onyx-test-automation and find out where the directories begin to overlap with the ones in your folder, but that will take a lot of "ls" commands throughout your pipeline and is not best practice.

Generic answered 8/2 at 6:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.