docker - Docker runner 本地构建登录非TTY设备

我在本地Linux尝试使用gitlab-runner构建项目。


docker-build:


 stage: build


 image: docker:latest


 script:


 - docker login -u"gitlab-ci-token" -p"$CI_JOB_TOKEN" $CI_REGISTRY # user"gitlab-ci-token" is automatically created by GitLab


 - docker build -t"$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME" target/


 - docker push"$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"




$ gitlab-ci-multi-runner exec docker --docker-privileged docker-build


Running with gitlab-ci-multi-runner 1.11.1 (a67a225)


 on ()


Using Docker executor with image docker:latest ...


Starting service docker:dind ...


Pulling docker image docker:dind ...


Waiting for services to be up and running...


Pulling docker image docker:latest ...


Running on runner--project-1-concurrent-0 via vanqyard...


Cloning repository...


Cloning into '/builds/project-1'...


done.


Checking out 70187b2d as docker-basic-conf...


Skipping Git submodules setup


Checking cache for docker-build/docker-basic-conf...


Successfully extracted cache


$ docker login -u"gitlab-ci-token" -p"$CI_JOB_TOKEN" $CI_REGISTRY


Error: Cannot perform an interactive login from a non TTY device


ERROR: Job failed: exit code 1


FATAL: exit code 1 



如何成功进行构建?

时间:

很可能你的项目没有指定变量$CI_JOB_TOKEN和$CI_REGISTRY,注意,变量不是共享的,只能为每个项目设置!

这也是你遇到错误消息的原因

标志需要一个参数:" -p "

当您尝试不带引号的docker登录时,这是正确的方法,因为否则$ CI_JOB_TOKEN不会被识别为变量,而只是一个由两个引号,一个美元符号和字符序列“ CI_JOB_TOKEN”组成的字符串 。

假设未设置变量,并且试图执行命令,


docker login -u"gitlab-ci-token" -p $CI_JOB_TOKEN $CI_REGISTRY




docker login -u"gitlab-ci-token" -p



-p标志后面没有密码,因此Docker尝试初始化交互式登录。

...