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.

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

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?