Gitlab-CI с Docker executor / usr / bin / bash: строка 90: git: команда не найдена - PullRequest
1 голос
/ 10 апреля 2020

У меня есть локальный сервер gitlab и gitlab-ci runner с docker executor.

Я хочу использовать gitlab-ci для создания (на первом этапе) моего проекта maven. Поскольку я использую плагин buildnumber-maven-plugin, я добавил к своему gitlab-ci.yml сервис git следующим образом:

image: maven:latest

services:
  - alpine/git:latest

# Cache goes here
cache:
  paths:
    - .m2/repository
    - frontend-app/node_modules/

# ENV variables goes  here

# Before script goes here

# Stages definition goes here
stages:
  - build

# Build stage
build:
  stage: build
  before_script:
    - mvn --version
    - git --version
  script:
    - mvn clean install --settings .ci/settings.xml
  artifacts:
    paths:
      - backend-app/target/*.jar

Но когда git --version выполнено, я получил command not found error. Это мой полный журнал консоли gitlab ci:

Running with gitlab-runner 12.9.0 (4c96e5ad)
   on securteck jrEY4-V2
Preparing the "docker" executor
 Using Docker executor with image maven:latest ...
 Starting service alpine/git:latest ...
 Pulling docker image alpine/git:latest ...
 Using docker image sha256:fe3295a34a932155290fdbba14d770c11f3dfe0e1e732d8e355cecbeec59e877 for alpine/git:latest ...
 Waiting for services to be up and running...
 *** WARNING: Service runner-jrEY4-V2-project-1-concurrent-0-alpine__git-0 probably didn't start properly.
 Health check error:
 ContainerStart: Error response from daemon: Cannot link to a non running container: /runner-jrEY4-V2-project-1-concurrent-0-alpine__git-0 AS /runner-jrEY4-V2-project-1-concurrent-0-alpine__git-0-wait-for-service/service (docker.go:1322:0s)
 Service container logs:
 2020-04-10T19:05:54.826814609Z usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
 2020-04-10T19:05:54.826879457Z            [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
 2020-04-10T19:05:54.826895945Z            [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
 2020-04-10T19:05:54.826910244Z            [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
 2020-04-10T19:05:54.826923359Z            <command> [<args>]
 2020-04-10T19:05:54.826935482Z 
 2020-04-10T19:05:54.826947063Z These are common Git commands used in various situations:
 2020-04-10T19:05:54.826959005Z 
 2020-04-10T19:05:54.826971038Z start a working area (see also: git help tutorial)
 2020-04-10T19:05:54.826982664Z    clone     Clone a repository into a new directory
 2020-04-10T19:05:54.826994349Z    init      Create an empty Git repository or reinitialize an existing one
 2020-04-10T19:05:54.827006426Z 
 2020-04-10T19:05:54.827017832Z work on the current change (see also: git help everyday)
 2020-04-10T19:05:54.827029626Z    add       Add file contents to the index
 2020-04-10T19:05:54.827040891Z    mv        Move or rename a file, a directory, or a symlink
 2020-04-10T19:05:54.827052743Z    restore   Restore working tree files
 2020-04-10T19:05:54.827064196Z    rm        Remove files from the working tree and from the index
 2020-04-10T19:05:54.827075878Z 
 2020-04-10T19:05:54.827087305Z examine the history and state (see also: git help revisions)
 2020-04-10T19:05:54.827099305Z    bisect    Use binary search to find the commit that introduced a bug
 2020-04-10T19:05:54.827111245Z    diff      Show changes between commits, commit and working tree, etc
 2020-04-10T19:05:54.827125099Z    grep      Print lines matching a pattern
 2020-04-10T19:05:54.827137183Z    log       Show commit logs
 2020-04-10T19:05:54.827149113Z    show      Show various types of objects
 2020-04-10T19:05:54.827160630Z    status    Show the working tree status
 2020-04-10T19:05:54.827172589Z 
 2020-04-10T19:05:54.827183674Z grow, mark and tweak your common history
 2020-04-10T19:05:54.827195529Z    branch    List, create, or delete branches
 2020-04-10T19:05:54.827207168Z    commit    Record changes to the repository
 2020-04-10T19:05:54.827218764Z    merge     Join two or more development histories together
 2020-04-10T19:05:54.827230406Z    rebase    Reapply commits on top of another base tip
 2020-04-10T19:05:54.827241931Z    reset     Reset current HEAD to the specified state
 2020-04-10T19:05:54.827253929Z    switch    Switch branches
 2020-04-10T19:05:54.827265678Z    tag       Create, list, delete or verify a tag object signed with GPG
 2020-04-10T19:05:54.827277537Z 
 2020-04-10T19:05:54.827300897Z collaborate (see also: git help workflows)
 2020-04-10T19:05:54.827314706Z    fetch     Download objects and refs from another repository
 2020-04-10T19:05:54.827327136Z    pull      Fetch from and integrate with another repository or a local branch
 2020-04-10T19:05:54.827339235Z    push      Update remote refs along with associated objects
 2020-04-10T19:05:54.827351266Z 
 2020-04-10T19:05:54.827362364Z 'git help -a' and 'git help -g' list available subcommands and some
 2020-04-10T19:05:54.827374869Z concept guides. See 'git help <command>' or 'git help <concept>'
 2020-04-10T19:05:54.827387595Z to read about a specific subcommand or concept.
 2020-04-10T19:05:54.827401411Z See 'git help git' for an overview of the system.
 *********
 Pulling docker image maven:latest ...
 Using docker image sha256:32cd4e857a56c5cfddaafaebc877764e2547e7bc23b4bc63cfc6a163c4ee3361 for maven:latest ...
Preparing environment
00:02
 Running on runner-jrEY4-V2-project-1-concurrent-0 via PAR-174582...
Getting source from Git repository
00:03
 Fetching changes with git depth set to 50...
 Reinitialized existing Git repository in /builds/securteck/securteck/.git/
 From http://195.154.233.19:8000/securteck/securteck
  * [new ref]         refs/pipelines/29 -> refs/pipelines/29
    b8a890e..17b4d1c  develop           -> origin/develop
 Checking out 17b4d1cd as develop...
 Skipping Git submodules setup
Restoring cache
00:02
 Checking cache for default-4...
 No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
 Successfully extracted cache
Downloading artifacts
00:02
Running before_script and script
00:02
 $ mvn --version
 Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
 Maven home: /usr/share/maven
 Java version: 14, vendor: Oracle Corporation, runtime: /usr/java/openjdk-14
 Default locale: en_US, platform encoding: UTF-8
 OS name: "linux", version: "4.15.0-76-generic", arch: "amd64", family: "unix"
 $ git --version
 /usr/bin/bash: line 90: git: command not found
Running after_script
00:02
Uploading artifacts for failed job
00:02
 ERROR: Job failed: exit code 1

Ответы [ 2 ]

2 голосов
/ 10 апреля 2020

Служба - это еще один docker контейнер, работающий во время вашей работы (например, база данных). docker образ alpine/git:latest не является службой , он используется для выполнения команды git. В ваших журналах вы видите, что git вызывается без команды.

Вместо использования service, вы должны использовать образ docker с git, установленным в нем, для запуска вашей работы. Таким образом, ваш скрипт сможет вызывать git.

1 голос
/ 11 апреля 2020

Если хотите, вы можете установить git в свой maven контейнер. Пример (заглушка) .gitlab-ci.yml:

image: maven:latest

myjob:
  script:
  - yum install -y git
  - git --version

Из журнала заданий CI:

$ git --version
 git version 1.8.3.1
...