Cannot run quarkus test on gitlab CI - gitlab-ci

Everything works on my machine. Problem is when I run tests on gitlab CI i get this error :
AuthenticationResourceTest > signinuser exists => returns a jwt token FAILED
java.lang.RuntimeException at QuarkusTestExtension.java:626
Caused by: java.lang.reflect.InvocationTargetException at NativeMethodAccessorImpl.java:-2
Caused by: java.util.concurrent.CompletionException at CompletableFuture.java:314
Caused by: java.lang.RuntimeException at TestResourceManager.java:457
Caused by: java.lang.IllegalStateException at DockerClientProviderStrategy.java:15
As my project is using Lombok could this be related to it? (but why does it work on my machine???).
Here is my .gitlab-ci:
stages:
- build
- test
build:
stage: build
image: openjdk:16
script: ./gradlew --build-cache quarkusBuild
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
test:
stage: test
image: openjdk:16
script: ./gradlew check
artifacts:
name: coverage
paths:
- $CI_PROJECT_DIR/build/jacoco-report
reports:
junit: jacoco.xml
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
Really struggling here.

Found the error.
Forgot that testcontainer needs docker dind
For those who struggle with this: test containers needs to run a docker container in order to create a test database.
That's the purpose of the dind service (docker in docker).
from
https://www.testcontainers.org/supported_docker_environment/continuous_integration/gitlab_ci/
Here is a sample .gitlab-ci.yml that executes test with gradle:
# DinD service is required for Testcontainers
services:
- name: docker:dind
# explicitly disable tls to avoid docker startup interruption
command: ["--tls=false"]
variables:
# Instruct Testcontainers to use the daemon of DinD.
DOCKER_HOST: "tcp://docker:2375"
# Instruct Docker not to start over TLS.
DOCKER_TLS_CERTDIR: ""
# Improve performance with overlayfs.
DOCKER_DRIVER: overlay2
test:
image: gradle:5.0
stage: test
script: ./gradlew test

Related

'app-deploy' job needs 'app-verify' job but 'app-verify' is not in any previous stage You can also test your .gitlab-ci.yml in CI Lint

Seeing Found errors in your .gitlab-ci.yml:
'app-deploy' job needs 'app-verify' job
but 'app-verify' is not in any previous stage
You can also test your .gitlab-ci.yml in CI Lint
Where as both stages are defined
Cache set as below
cache:
key: ${CI_PIPELINE_ID}
paths:
- $CI_PROJECT_DIR/
- $CI_PROJECT_DIR/$CONTEXT/
Stages defined as below, snippets
app-build:
stage: build
# Extending the maven-build function from maven.yaml
extends: .maven-build
app-deploy:
stage: deploy
extends: .docker-publish
cache:
key: ${CI_PIPELINE_ID}
paths:
- $CI_PROJECT_DIR/
- $CI_PROJECT_DIR/$CONTEXT/
variables:
DOCKERFILE: Dockerfile
CONTEXT: app
OUTPUT: app.war
needs:
- app-build
- app-verify
dependencies:
- app-build
- app-verify
How to resolve the above error.
Error should go away and no error in pipeline run.

Vue deployment to Heroku with CircleCI failing: fatal: Not a git repository (or any of the parent directories): .git

Having trouble deploying to HEROKU with CircleCI. I have already tested deploying git push heroku master to heroku manually, which is working. However when I use CircleCI, deployment no longer works.
Github repo url: https://github.com/dulerong/vue-test-circleci
I have set HEROKU environment variables in CircleCI project setting.
HEROKU_API_KEY=my_key
HEROKU_APP_NAME=my_app_name
Error message follows.
#!/bin/bash -eo pipefail
if false;then
force="-f"
fi
heroku_url="https://heroku:$HEROKU_API_KEY#git.heroku.com/$HEROKU_APP_NAME.git"
if [ -n "$CIRCLE_BRANCH" ]; then
git push $force $heroku_url $CIRCLE_BRANCH:main
elif [ -n "$CIRCLE_TAG" ]; then
git push $force $heroku_url $CIRCLE_TAG^{}:main
else
echo "No branch or tag found."
exit 1
fi
fatal: Not a git repository (or any of the parent directories): .git
Exited with code exit status 128
CircleCI received exit code 128
Below is my circleCI config.yml
version: 2.1
orbs:
heroku: circleci/heroku#1.2.5
jobs:
build-job:
working_directory: ~/repo
docker:
- image: circleci/node:12.18.2
steps:
- checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Build
command: npm run build
- save_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- run:
name: lint
command: npm run lint
- run:
name: test
command: npm run test:unit
deploy-job:
working_directory: ~/repo
docker:
- image: circleci/node:12.18.2
steps:
- attach_workspace:
at: ~/repo
- heroku/deploy-via-git
workflows:
version: 2.1
deploy:
jobs:
- build-job
- deploy-job:
requires:
- build-job
filters:
branches:
only: master
I have linked CircleCI to my Github repo
I have created .circleci folder config.yml
I have created an app on heroku, which works when I deploy manually
The build part of my CircleCI works, however deployment does not work
Any help is appreciated, thanks in advance.
Found out what I was missing.
- checkout
I was missing this line of code in my deploy-job. Hence after changing the deploy-job yml config code to following, everything worked.
deploy-job:
working_directory: ~/repo
docker:
- image: circleci/node:12.18.2
steps:
- checkout<--- INSERT THIS CODE HERE!!!!
- attach_workspace:
at: ~/repo
- heroku/deploy-via-git
Reason: checkout command leads CircleCI to the root directory of your project. Hence without this line of code, you're looking at a folder directory that's not even the root of your project.
Other useful command include
- run:
name: show directory
command: pwd
- run:
name: look in directory
command: ls -ltr
If you place those commands beneath checkouk, and look into the job progress in your CircleCI project, you can actually see which directory CircleCI is looking at, during that exact moment, very useful to check which directory CircleCI is working in. I put in those two commands and found out that my CircleCI was not looking at the root directory, hence discovering my problem.
Took me a few hours to figure this out!!!

Bitbucket pipeline not running Chromedriver executable

So I'm running in to an error where I have a simple front end login test to a website using selenium. When I run the test in the bitbucket pipelines I'm running in to this error
java.lang.IllegalStateException: The driver executable does not exist: /opt/atlassian/pipelines/agent/build\chromedriver.exe
Bitbucket yml file
image: gradle:6.6.0
pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- gradle
script:
- gradle build
after-script:
- pipe: atlassian/checkstyle-report:0.2.0
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.4.3
Does anyone know what the issue may be ?
I see 2 things:
You are specifying the driver file so the route could be incorrect.
java.lang.IllegalStateException: The driver executable does not exist: /opt/atlassian/pipelines/agent/build\chromedriver.exe
You are using a gradle image
image: gradle:6.6.0
but I don't think that you have a driver/browser in that image.
You will need to add another image with a browser, like this https://hub.docker.com/r/selenium/standalone-chrome, you can find more examples here https://github.com/SeleniumHQ/docker-selenium and add it to your file. Something like this:
image: gradle:6.6.0
pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- gradle
services:
- chrome
script:
- gradle build
after-script:
- pipe: atlassian/checkstyle-report:0.2.0
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.4.3
definitions:
services:
chrome:
image: selenium/standalone-chrome
You will need to change your code to use a RemoteWebDriver
https://www.selenium.dev/documentation/en/remote_webdriver/remote_webdriver_client/

Executing reckonTagCreate from gitlab ci with authentication failure

I have setup my CI so that I can manually create a release-tag when all tests succeeds for a new commit on master branch. For this I have created a manual step in the CI config like so:
.release-template:
stage:
releasing
dependencies:
- assemble
script:
- ./gradlew reckonTagPush -Preckon.scope=$scope -Preckon.stage=$stage -Dorg.ajoberstar.grgit.auth.username=$GIT_USER -Dorg.ajoberstar.grgit.auth.password=$GIT_PASSSWORD
only:
- master
when: manual #ONLY MANUAL RELEASES, ONLY FROM MASTER
release-major:
extends: .release-template
variables:
scope: major
stage: final
release-minor:
extends: .release-template
variables:
scope: minor
stage: final
release-patch:
extends: .release-template
variables:
scope: patch
stage: final
This setup fails with an authentication error.
Execution failed for task ':reckonTagPush'.
> org.eclipse.jgit.api.errors.TransportException: https://gitlab-ci-token#gitlab.com/<group>/<project>.git: not authorized
I am running this on gitlab.com on a shared runner.
The username and password are configured in gitlab ci variables for the project. When running this locally inside the same docker image that is used in the gitlab runner, it works fine. So there must be something special about the way the gitlab runner is executing the gradle tasks, or communicating with the gitlab git repo.
Solved the issue with access to pushing to the git repo by adding the following script :
script:
- url_host=`git remote get-url origin | sed -e "s/https:\/\/gitlab-ci-token:.*#//g"`
- git remote set-url origin "https://gitlab-ci-token:$GIT_TOKEN#$url_host"
- ./gradlew reckonTagPush -Preckon.scope=$scope -Preckon.stage=$stage -Dorg.ajoberstar.grgit.auth.username="$GIT_USER" -Dorg.ajoberstar.grgit.auth.password="$GIT_TOKEN"
The notably changes here are setting the git remote url, as well as surrounding the gitlab ci variables with " when passing them to the reckon plugin

Using redis with Gitlab CI

I am currently using serverless framework and setting up gitlab ci using shared runner.
Following is my gitlab-ci.yml:
image: node:latest
services:
- redis
cache:
paths:
- node_modules/
- java/
stages:
- build
- test
- review
- staging
- production
build:
stage: build
script:
- npm install
artifacts:
paths:
- node_modules/
install:java:
stage: build
script:
- apt-get update
- apt-get install -y default-jre default-jdk openjdk-7-jre openjdk-7-jdk
- apt-get update
- sls dynamodb install
artifacts:
paths:
- java/
connect:
image: redis
script:
- redis-cli -h redis PING
unit test:
stage: test
script:
- sls dynamodb start
- babel-node ./aws/createDB.js
- npm run unit
dependencies:
- build
- install:java
unit test job requires redis and is not able to connect. Following error gets thrown, when unit test job starts:
Error while creating redis client: Error: Redis connection to
127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
Can someone point out what's wrong with current config file, thanks!
The host address of the redis service is redis not 127.0.0.1 or localhost.
So make sure you set the host for the redis service to redis in all of your scripts and configuration files.
Just to make people's life easier, I list an example .gitlab-ci.yml to configure Redis in Gitlab CI.
services:
- redis:latest
stages:
- test
test:
script:
- echo "hello world!"
stage: test
variables:
REDIS_PORT: 6379
REDIS_HOST: redis
REDIS_URL: redis://redis:6379