GitLab CI configuration is invalid: stages config should be an array of strings - gitlab-ci

I getting an error on stages on that pipeline.
GitLab CI configuration is invalid: stages config should be an array of strings.
stages:
-test
-run
image: python:latest
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
test-asamasi:
stage: test
script:
- python --version
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- python sslkontrol.py test
calistirma:
stage: run
script:
- python sslkontrol.py

On small mistake on the stages, you need to add an extra space between the - and test

I have tested your pipeline file above and I was able to get it working by adding space between - character and stage name(e.g - test) as shown below:
stages:
- test
- run
image: python:latest
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
test-asamasi:
stage: test
script:
- python --version
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- python sslkontrol.py test
calistirma:
stage: run
script:
- python sslkontrol.py
Recommendations
Now its easier to visualize, lint/validate your gitlab pipeline(e.g ) from within Gitlab console using this instructions Validate GitLab CI/CD configuration

Related

How do I add 'exists:' to a rule?

I want to run a Gitlab pipeline stage after pushing a commit on the 'master' branch and a directory named 'tests' exists in the project root. Here is the relevant snippet from .gitlab-ci.yaml that defines the stage and its rules:
stage: test
image: python:3.10.3-bullseye
rules:
- if: $CI_COMMIT_BRANCH == "master"
exists:
- tests
before_script: *setup-python
script:
- pip install -e .[dev]
- pytest tests/
However, after a commit on the master branch, it remains disabled. I'm a bit fuzzy on the syntax, despite reading the docs carefully. Does anyone know how to achieve what I'm after?
I think you should define the job like:
stage: test
image: python:3.10.3-bullseye
rules:
- if: $CI_COMMIT_BRANCH == "master"
- exists:
- tests/**/*.py
before_script: *setup-python
script:
- pip install -e .[dev]
- pytest tests/
reference:
https://docs.gitlab.com/14.10/ee/ci/yaml/#rulesexists
https://docs.gitlab.com/14.10/ee/ci/yaml/#onlyrefs--exceptrefs

Execute GitLab job only if files have changed in a subdirectory, otherwise use cached artefact in following job

I have a simple pipeline, comparable to this one:
image: docker:20
variables:
GIT_STRATEGY: clone
stages:
- Building - Frontend
- Building - Backend
include:
- local: /.ci/extensions/ci-variables.yml
- local: /.ci/extensions/docker-login.yml
Build Management:
stage: Building - Frontend
image: node:14-buster
script:
# Install needed dependencies for building
- apt-get update
- apt-get -y upgrade
- apt-get install -y build-essential
- yarn global add #quasar/cli
- yarn global add #vue/cli
# Install required modules
- cd ${CI_PROJECT_DIR}/resources/js/management
- npm ci --cache .npm --prefer-offline
# Build project
- npm run build
# Create archive
- tar czf ${CI_PROJECT_DIR}/dist-resources-js-management.tar.gz *
cache:
policy: pull-push
key:
files:
- ./resources/js/management/package-lock.json
paths:
- ./resources/js/management/.npm/
artifacts:
paths:
- dist-resources-js-management.tar.gz
Build Docker:
stage: Building - Backend
needs: [Build Management, Build Administration]
dependencies:
- Build Management
- Build Administration
variables:
CI_REGISTRY_IMAGE_COMMIT_SHA: !reference [.ci-variables, variables, CI_REGISTRY_IMAGE_COMMIT_SHA]
CI_REGISTRY_IMAGE_REF_NAME: !reference [.ci-variables, variables, CI_REGISTRY_IMAGE_REF_NAME]
before_script:
- !reference [.docker-login, before_script]
script:
- mkdir -p {CI_PROJECT_DIR}/public/static/management
- tar xzf ${CI_PROJECT_DIR}/dist-resources-js-management.tar.gz --directory ${CI_PROJECT_DIR}/public/static/management
- docker build
--pull
--label "org.opencontainers.image.title=$CI_PROJECT_TITLE"
--label "org.opencontainers.image.url=$CI_PROJECT_URL"
--label "org.opencontainers.image.created=$CI_JOB_STARTED_AT"
--label "org.opencontainers.image.revision=$CI_COMMIT_SHA"
--label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME"
--tag "$CI_REGISTRY_IMAGE_COMMIT_SHA"
-f .build/Dockerfile
.
I now want the first job to be executed under the following conditions:
Something has changed in the directory ${CI_PROJECT_DIR}/resources/js/management
This job has not yet created an artifact.
The last job should therefore always be able to access an artifact. If nothing has changed in the directory, it does not have to be created anew each time. If it did not exist before, it must of course be created.
Is there a way to map this in the GitLab Ci?
If I currently specify the dependencies and then work with only:changes: for the first job, GitLab complains if the job is not executed. Likewise with needs:.

Gitlab CI/CD running Unit tests

I need to run unit tests on gitlab pipeline.
Here's my .gitlab-ci.yml:
stages:
- build
image: napp/php-ci:7.4-fpm
services:
- name: mysql:5.7
alias: mysql
variables:
MYSQL_ROOT_PASSWORD: pass_root
MYSQL_DATABASE: db_test
MYSQL_USER: user
MYSQL_PASSWORD: test
DATABASE_URL: 'mysql://user:test#mysql:3306/db_test'
build:
stage: build
only:
- master
- staging
services:
- mysql:5.7
script:
- apt-get update
- apt-get install zip unzip
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php
- php -r "unlink('composer-setup.php');"
- php composer.phar install
- php bin/console app:deploy:symfony:local
- ./vendor/bin/phpunit
On gitlab I have error: Access denied for user 'user'#'%' to database 'db_test_test'
Why it does not make tests on db_test but on 'db_test_test'`?
Can you please help me so I could run it appropriate db - db_test
Check your env.test file or any other environment file that you are using for testing. There will be a line which adds a prefix _test to your database name.

Gitlab after push tag

Is it possible to configure the gitlab-yml of the project in such a way that after the tag has been pushed out it can run several commands ? If so, how do you get it? I would also like to define the variables that I would like to use in these several commands.
My gitlab-ci looks like:
stages:
- build
- deploy
build:
stage: build
script:
- composer install --no-ansi
- vendor/bin/phar-composer build
artifacts:
paths:
- example.phar
tags:
- php:7.0
deploy:
stage: deploy
only:
- tags
dependencies:
- build
script:
- cp example.phar /opt/example/
tags:
- php:7.0
It's about running example.phar bin/console command1 $VARIABLE1 $VARIABLE2 $VARIABLE3 $VARIABLE4.
Please help me because I am not completely familiar with these matters.
You can trigger a job when one tag is pushed using only parameter:
build:
stage: build
image: alpine:3.6
script:
- echo "A tag has been pushed!"
only:
- tags

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