GitLab CI在Docker构建的作业上无效参数

时间:2018-05-23 10:29:47

标签: docker gitlab gitlab-ci-runner

所以我正在尝试设置我的Gitlab CI来触发git push上的作业来构建和部署我的Docker。这是我使用的.gitlab-ci.yml文件,基于Gitlab文档(Elixir yml)中的一个示例。

stages:
  - build

build:
  before_script:
    - docker build -f Dockerfile.build -t ci-project-build-$CI_PROJECT_ID:$CI_BUILD_REF .
    - docker create
      -v /build/deps 
      -v /build/_build
      -v /build/rel
      -v /root/.cache/aceapp/
      --name build_data_$CI_PROJECT_ID_$CI_BUILD_REF busybox /bin/true
  tags:
    - docker
  stage: build
  script: 
    - docker run --volumes-from build_data_$CI_PROJECT_ID_$CI_BUILD_REF --rm -t ci-project-build-$CI_PROJECT_ID:$CI_BUILD_REF

推送到GitLab实例时的输出是:

Running with gitlab-runner 10.7.2 (b5e03c94)
on my.host.rhel.runner 8f724ea7
Using Shell executor...
Running on my.host.local...
Fetching changes...
HEAD is now at 14351c4 Merge branch 'Development' into 'master'
From https://my.host.example/zalmosc/ace-app
   14351c4..9fa2d43  master     -> origin/master
Checking out 9fa2d435 as master...
Skipping Git submodules setup
$ # Auto DevOps variables and functions # collapsed multi-line command
$ setup_docker
$ build
Logging to GitLab Container Registry with CI credentials...
Login Succeeded

Building Dockerfile-based application...
invalid argument "/master:9fa2d4358e6c426b882e2251aa5a49880013614b" for t: Error parsing reference: "/master:9fa2d4358e6c426b882e2251aa5a49880013614b" is not a valid repository/tag: invalid reference format
See 'docker build --help'.
ERROR: Job failed: exit status 1

我理解docker标签无效(before_script:是否真的根据名称触发?),我正在寻找有关a)解决方案的帮助b)我如何能够了解更多有关要求的信息对于基于默认设置构建docker的管道。我是否需要在本地标记我的docker镜像,然后以某种方式将其添加到我的git提交中?

3 个答案:

答案 0 :(得分:1)

您的代码不能以'/'开头:

Base

答案 1 :(得分:0)

事情是-t标记您的Docker镜像。请参阅文档here

标记应格式化为name:version,并且您为其提供的/master:9fa2d4358e6c426b882e2251aa5a49880013614b不是有效标记。您可以尝试在/

之前删除master

答案 2 :(得分:0)

如果不使用内置注册表,则可能必须将CI_REGISTRY_IMAGE值设置为某些值。看来,如果您不进行设置,它将设置为/ master并导致此错误。您可以在配置项设置页面中或在制作新管道时进行设置。例如CI_REGISTRY_IMAGE gitlab.com/user/project