dtfbj24048 2019-07-19 14:56
浏览 100
已采纳

Golang和Gitlab持续集成

I am close to achieve a complete (without testing stage) continuous integration in Gitlab with a Golang software.

It fails when I am trying to build the Docker image at the docker login step.

Here is my .gitlab-ci.yml :

stages:
  - build

variables:
  REGISTRY: registry.gitlab.com
  GO_PROJECT: mysoftware

build_golang_binary:
  image: golang:latest
  stage: build
  before_script:
    - mkdir -p ${GOPATH}/src/${GO_PROJECT}
    - cp -r ${CI_PROJECT_DIR}/* ${GOPATH}/src/${GO_PROJECT}/
    - cd ${GOPATH}/src/${GO_PROJECT}
    - go get
  script:
    - cd ${GOPATH}/src/${GO_PROJECT}
    - go build

build_docker_image:
  image: docker:latest
  stage: build
  script:
    - docker login $REGISTRY
    - docker build --no-cache -t ${REGISTRY}/me/${GO_PROJECT} .
    - docker push ${REGISTRY}/me/${GO_PROJECT}

Here is the error I am getting : $ docker login $REGISTRY Error: Cannot perform an interactive login from a non TTY device

I thought that the credentials would be provided into this CI process.. Apparently, they are not.

What is the best option to solve this ?

  • 写回答

1条回答 默认 最新

  • doulin2025 2019-07-22 19:25
    关注

    My answer assumes you're using GitLab.com for both the CI and Registry (based on registry.gitlab.com being in your .gitlab-ci.yml example above.

    You can utilize several environment variables available in the GitLab CI job to authenticate to the GitLab Registry:

    • docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

    The $CI_REGISTRY_PASSWORD is an ephemeral token that is only valid for the duration of your job. You can learn more in Authenticating to the Container Registry documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?