Gitlab-runner本地构建 - 从非TTY设备登录 [英] Gitlab-runner local build - login from non TTY device

查看:4592
本文介绍了Gitlab-runner本地构建 - 从非TTY设备登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Linux上的gitlab-runner在本地构建我的项目。

  docker-build:
stage:build
image:docker:最新
脚本:
- docker login -ugitlab-ci-token-p$ C​​I_JOB_TOKEN$ CI_REGISTRY#用户gitlab-ci-token由GitLab
- docker build -t$ CI_REGISTRY_IMAGE :$ CI_COMMIT_REF_NAMEtarget /
- docker push$ CI_REGISTRY_IMAGE:$ CI_COMMIT_REF_NAME

不幸的是我的尝试结束了关于码头登录的错误无法从非TTY设备执行交互式登录。

  $ gitlab-运行与gitlab-ci多人1.11.1(a67a225)
on()
使用Docker执行器与图像docker:最新...
启动服务码头:dind ...
拉泊码头图像docker:dind ...
等待服务启动并运行...
拉泊码头图像码头:最新...
运行在跑步者 - 项目1并发0通过vanqyar d ...
克隆资料库
克隆到'/ builds / project-1'...
完成。
签出70187b2d作为docker-basic-conf ...
跳过Git子模块安装
检查docker-build / docker-basic-conf ...的缓存
成功解压缩缓存
$ docker login -ugitlab-ci-token-p$ C​​I_JOB_TOKEN$ CI_REGISTRY
错误:无法从非TTY设备执行交互式登录
错误:作业失败:退出代码1
致命:退出代码1

我的问题是有人偶然遇到这个问题,如何成功执行构建?

解决方案

很可能您没有指定变量 $ CI_JOB_TOKEN $ CI_REGISTRY 为您正在开展的项目。请注意,变量不共享,并且仅针对每个项目设置



这也是为什么您遇到错误消息


标志需要一个参数:'p'in -p


当您尝试使用不带引号的码头登录时,这是正确的方式,因为否则 $ CI_JOB_TOKEN 不被识别为变量,但它只是一个由两个引号组成的字符串,一个美元符号和字符序列CI_JOB_TOKEN。



假设您的变量未设置并尝试执行命令

  docker login -ugitlab-ci-token-p $ CI_JOB_TOKEN $ CI_REGISTRY 

变量被评估,您的命令基本如下所示:

  docker login -ugitlab-ci-token-p 

-p 标志后面没有密码,对于tha t原子码头试图初始化一个交互式登录。



您可以通过尝试输出您的变量,当您包含命令 echo $ CI_JOB_TOKEN 你的.gitlab-ci.yml


I'm trying to build my project locally using gitlab-runner on Linux.

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"

Unfortunately my attempts end with error about "docker login" not being able to perform interactive login from non-TTY device.

$ 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 

My question is has anybody stumbled upon this issue and how to succesfunlly perform build?

解决方案

Most likely you did not specify the variables $CI_JOB_TOKEN and $CI_REGISTRY for the project you are working on. Note that variables are not shared and are only set per project!

That's also why you encounter the error message

"flag needs an argument: 'p' in -p"

when you try to do the docker login without the quotes, which is the right way because otherwise $CI_JOB_TOKEN is not recognized as a variable, but it is simply a string consisting of two quotes, a dollar sign and the sequence of chars "CI_JOB_TOKEN".

Assuming your variables are not set and you try to execute the command

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

the variables are evaluated and your command essentially looks like that:

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

The -p flag is not followed by a password and for that reason docker tries to initialize an interactive login.

You can verify this by trying to output your variables when you include the command echo $CI_JOB_TOKEN in your .gitlab-ci.yml

这篇关于Gitlab-runner本地构建 - 从非TTY设备登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆