I am trying to create the correct .gitlab-ci.yml file . This is for online gitlab.com not for self-hosted gitlab. Most (if not all) of the documentation is for a self-service gitlab instance.
I want to run my Mocha-Chai tests on an embedded container, and when the tests pass, I want to create an image and save it in the Gitlab registry with a tag that matches my last git tag.
Control part
I canβt run the tests, no matter what I try, I always get Mocha not found.
Below is my .yml file. The build section is working. The problem lies in the test section and in the part of the docker tag in the release image. I got the yml file from gitlab official documentation gitlab official documentation
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- release
- deploy
variables:
CONTAINER_TEST_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:latest
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com/edelacruz/cloudtrader-microservices
build:
stage: build
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
test:
stage: test
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE npm install && npm test
I also tried
test:
stage: test
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE npm test
and
test:
stage: test
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE npm install mocha -g
- docker run $CONTAINER_TEST_IMAGE npm install chai -g
- docker run $CONTAINER_TEST_IMAGE npm test
all the same result:
sh: mocha: not found
test script in package.json
"test": "mocha ./Test",
I tried using mocha and chai in devDependencies and in dependencies.
"devDependencies": {
"chai": "^4.0.2",
"mocha": "^3.4.2"
}
"dependencies": {
"chai": "^4.0.2",
"mocha": "^3.4.2"
},
Tag part
variables:
CONTAINER_TEST_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:latest
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com/edelacruz/cloudtrader-microservices
release-image:
stage: release
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE:$CI_COMMIT_TAG
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
Image release works if I donβt include part of the tag. But I really want my image to be tagged with git, and not with the help of lattests or wizards.
$ docker tag $ CONTAINER_TEST_IMAGE $ CONTAINER_RELEASE_IMAGE: $ CI_COMMIT_TAG Syntax analysis error: "registry.gitlab.com/edelacruz/cloudtrader-microservices:" is not a valid repository / tag: invalid link format ERROR: job failed: exit code: 1
