Reputation: 597
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 ?
Upvotes: 0
Views: 889
Reputation: 2705
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.
Upvotes: 2