I would like to just use GitLab CI to run test only not to deploy my app. I manage to assembly this .yml
file:
image: java:8
stages:
- build
- test
build:
stage: build
script: ./gradlew build
artifacts:
paths:
- build/libs/myApp-4.0.0-SNAPSHOT.jar
unitTests:
stage: test
script:
- ./gradlew test
And in the GitLab Pipeline I get the following error:
ar.com.sebasira.myApp.myAppApplicationTests > contextLoads FAILED java.lang.IllegalStateException Caused by: org.springframework.beans.factory.BeanCreationException Caused by: org.springframework.beans.BeanInstantiationException Caused by: org.springframework.beans.factory.BeanCreationException Caused by: org.springframework.beans.BeanInstantiationException Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException
I'm guessing this could be related to database, right? I need to provide that database with credentials in my Server where the runner is?
If so, how should I do it? I'currently using application.properties
file to define the connection to the DB.
And one more question... in the .gitlab-ci.yml
file I need to put the path to the .jar
but that filename will change everytime I update the version of my app. Do I need to manually change it?
As you are starting the whole Spring context with this test (I think it's the generated standard test from Spring Boot) with the annotations @RunWith(SpringRunner.class)
and @SpringBootTest
you have to provide a datasource. You can do one of the following:
- Specify the database credentials in your
application.properties
insrc/test/resources
(you could provide a test database on your database server as I wouldn't connect to your production database on every test) - Use an embedded
H2
for this test - Use https://www.testcontainers.org/ to provide a real and fresh database for your Spring application test
Regarding your GitlabCI question: Just use *
to match any .jar
no matter which version: - build/libs/myApp-*.jar