I'm newer in GitLab. I have some tests and I want to run them by CI\CD. Can you help me to configure my .yml.
I should run testng.xml
This is my project:
enter image description here
path to my tests is: src/test/java/tests/"files with tests"
my .yml file:
image: maven:3-jdk-7
build:
script: mvn install -b
I think this should work.gitlab docs
test:
image: xxxx/xxx-test:latest
stage: test
script:
- pwd
- mvn test
Related
I have a maven project. Inside it I have a _models/ folder where I have some .puml files.
I would like to generate the .pngs from those plantuml files each time I commit.
This is my .gitlab-ci.yml
stages:
- test
- build
- uml
.maven:
image: maven:3.6.3-jdk-11
test:
extends: .maven
script:
- mvn test
build:
extends: .maven
script:
- mvn package -B
uml:
image: miy4/plantuml
script:
- plantuml -charset UTF-8 ./_models/sequence_diagram.puml
- plantuml -charset UTF-8 ./_models/class_diagram.puml
- plantuml -charset UTF-8 ./_models/object_diagram.puml
The pipeline passes but the diagrams.png are not created in the _models folder. Do you know why?
In the GitLab pipelines it says: No diagram found but when I run locally those commands everything works fine
Thanks :)
I have a project /templates where I want to add a common ci_settings.xml that sets some defaults for maven commands.
I then want to reuse this template in another project:
.gitlab_ci.yml:
image: maven:3.8.4-eclipse-temurin-11
include:
project: 'all/templates'
ref: master
file:
- 'ci_settings.xml'
deploy:
stage: deploy
script: mvn deploy -s ci_settings.xml
Result:
Found errors in your .gitlab-ci.yml:
Included file `ci_settings.xml` does not have YAML extension!
How can I actually make use of this external file, if not via include?
You can use include only with yml files. But you can clone the /templates project in your pipeline via CI_JOB_TOKEN and use it this way. As you don't need the commit history here you can set the depth to 1.
image: maven:3.8.4-eclipse-temurin-11
deploy:
stage: deploy
script:
- git clone --depth 1 https://gitlab-ci-token:${CI_JOB_TOKEN}#your_path_to_templates_project.git templates
- mvn deploy -s templates/ci_settings.xml
UPDATE: added when:always under artifacts fixed the issue, since the unit tests were failing, so the coverage folder was not created as an artifact
When unit tests are run, a coverage folder is created. I want to save that coverage folder as an artifact in the pipeline so that sonarqube can access the reports in that folder to give an accurate coverage report. When I push up any code, I'm not seeing the coverage folder being saved as an artifact after the unit tests are run in the pre-build stage, so it is not being passed along to sonarqube in the build stage.
This is the yml file:
stages:
- Pre-Build
- Build
- etc.
Unit Tests:
stage: Pre-Build
allow_failure: true
script:
- npm ci
- npm run test
artifacts:
paths:
- coverage
when: always
SonarQube:
stage: Build
needs: ['Unit Tests']
except:
refs:
- tags
try add slash in dir-path
Unit Tests:
stage: Pre-Build
allow_failure: true
script:
- npm ci
- npm run test
artifacts:
paths:
- coverage/
when: always
Expecting:CI need to trigger build and test then it should scan for dependencies vulnerability
Current Behaviour CI trigger but only run build and test not running Dependency-Scanning.gitlab-ci.yml
stages:
- build
- test
build:
stage: build
script:
- echo "Building"
test:
stage: test
script:
- echo "Testing"
include:
- template: Dependency-Scanning.gitlab-ci.yml
Dependency-Scanning.gitlab-ci.yml can be found in the following URL
https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml
You can try moving it to the top of the file. Works for me.
Can you toss the error in your post? Are you getting something like this if you use the CI linter? https://gitlab.com/amishpanda/cheatsheet/-/ci/lint
Found errors in your .gitlab-ci.yml:
dependency_scanning job: stage parameter should be .pre
setup
build
.post
You can also test your .gitlab-ci.yml in CI Lint
I'm creating a simple java project using Gradle which generates a test report (i.e. BDD Cucumber, JUnit, etc.). This project is deployed to Gitlab where the project is built as part of the Gitlab CI process.
My JUnit reports are generated in the folder build/reports/tests/test/ relative to the project path (as an index.html and some CSS files, etc.).
How do I configure my .gitlab-ci.yml to publish the content of build/reports/tests/test/ to the Gitlab Pages even after my test cases fail?
This is what I have in my .gitlab-ci.yml: (My repo can be found HERE)
Version 1: Doesn't publish anything to pages
image: java:8-jdk
stages:
- test
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
test:
stage: test
script:
- mkdir public
- ./gradlew test
artifacts:
paths:
- build/reports/tests/test/
only:
- master
after_script:
- mv build/reports/tests/test/* public
Version 2: Doesn't execute the deploy stage since test has failed.
image: java:8-jdk
stages:
- test
- deploy
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
test:
stage: test
script:
- ./gradlew test
artifacts:
paths:
- build/reports/tests/test/
pages:
stage: deploy
dependencies:
- test
script:
- mkdir public
- mv build/reports/tests/test/* public
artifacts:
paths:
- public
only:
- master
I solved the issue by adding the when: always at the end of my pages stage. It now executes the stage regardless of exit code from the dependent stage.