Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI fails with ERROR: Job failed: exit code 1

I am pretty new to gitlab ci and I have a project with a pre-existing gitlab configuration which was running fine but after pushing a few code changes, it has now completely stopped working and I can't figure out why. Here is the .gitlab-ci.yml

stages:
  - build
  - deploy

variables:
  DOCKER_HOST: tcp://localhost:2375

assets:
  stage: build
  image: node:10-alpine
  script:
    - npm ci
    - NODE_ENV=production npm run build
  artifacts:
    expire_in: 1 day
    paths:
      - public/assets
  tags:
    - docker

package:
  stage: deploy
  image: php:7.3-cli-alpine
  dependencies:
    - assets
  before_script:
    - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    - php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    - php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    - php -r "unlink('composer-setup.php');"
  script:
    - composer install --prefer-dist --no-progress --optimize-autoloader --no-scripts
    - rm -fr .git
  artifacts:
    expire_in: 1 day
    paths:
      - .
  tags:
    - docker

docker:
  stage: deploy
  image: docker:latest
  services:
    - docker:18-dind
  dependencies:
    - assets
  script:
    - docker build -t $CI_REGISTRY_IMAGE:latest .
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:latest
  only:
    - master
  tags:
    - docker

deploy:
  stage: deploy
  image: php:7.3-cli-alpine
  dependencies:
    - assets
  before_script:
    - curl -LO https://deployer.org/deployer.phar
    - mv deployer.phar /usr/local/bin/dep
    - chmod +x /usr/local/bin/dep
    - apk add --update openssh rsync
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan -t rsa domain.co.uk >> /root/.ssh/known_hosts
  script:
    - dep deploy -p --tag="$CI_COMMIT_TAG"
  only:
    - tags
  tags:
    - docker

I am consistently getting the following error and I am wondering what has changed and if it is the server or gitlab-ci causing the following issue. I checked the server and it's running fine but there is no docker installed there and I presume the docker is not supposed to be installed on the server for what it is trying to do anyways?

Checking out a50d58fd as master...
 Skipping Git submodules setup
Downloading artifacts for assets (447059035)...
00:01
 Downloading artifacts from coordinator... ok        id=447059035 responseStatus=200 OK token=cp4GCzgJ
$ docker build -t $CI_REGISTRY_IMAGE:latest .
00:02
 time="2020-02-24T03:53:41Z" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial tcp [::1]:2375: connect: connection refused"
 error during connect: Post http://localhost:2375/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=sja0dvuf6gm0w8tneigulo3ha&shmsize=0&t=registry.gitlab.com%2Fnir.npl%2Fbrayleys-honda%3Alatest&target=&ulimits=null&version=1: context canceled
 ERROR: Job failed: exit code 1
like image 639
Niraj Pandey Avatar asked Feb 24 '20 04:02

Niraj Pandey


People also ask

Why is my GitLab job not working?

If you don’t specify a Docker image for your job, the GitLab runner executing your job will use the default image, in this case: ruby:2.5. The problem with this is that this Docker container does not have node and npm installed, and this is why the job is failing.

Is GitLab not recognizing the configuration deploy review as a job?

Have a look at the following configuration: - sh ./deploy.sh ... Can you spot the issue? GitLab is not recognizing the configuration deploy review as a job. The problem here is that this job configuration is missing the script block. Because the script is not properly indented, it has been defined as a variable.

Why is my merge request not working in GitLab?

If you have a variable which you need in Merge Requests / branches, this variable needs to be unprotected, as most likely the branch itself is unprotected. I hope this list of common GitLab CI errors and solutions helped you get started fixing your problem.

Is GitLab running on the 18 major fixes to Docker?

It seems docker updated their latest stable images and gitlab has not updated their runners yet, changing the images to be on the 18 major fixes these issues, eg: image: docker:18-git variables: DOCKER_HOST: tcp://docker:2375/ DOCKER_DRIVER: overlay2 services: - docker:18-dind


1 Answers

Check if this is similar to this thread from a year ago:

It seems docker updated their latest stable images and gitlab has not updated their runners yet, changing the images to be on the 18 major fixes these issues, eg:

image: docker:18-git

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2

services:
  - docker:18-dind

In you case, a year later, that would be docker:19-dind, especially if you are using image: docker:latest, which is not a good practice, because "latest" can vary at any time.
image: docker:19-git would be preferable.

like image 156
VonC Avatar answered Oct 26 '22 23:10

VonC