我有一个..gitlab ci.yml文件,它使用golang映像和稍后的MySql映像作为服务.
吉尔布-西姆.
stages:
- test
- build
- art
image: golang:1.9.2
variables:
BIN_NAME: alltools
ARTIFACTS_DIR: artifacts
GO_PROJECT: alltools
GOPATH: /go
before_script:
- mkdir -p ${GOPATH}/src/${GO_PROJECT}
- mkdir -p ${CI_PROJECT_DIR}/${ARTIFACTS_DIR}
- go get -u github.com/golang/dep/cmd/dep
- go get -u github.com/fatih/color
- go get -u github.com/go-sql-driver/mysql
- cp -r ${CI_PROJECT_DIR}/* ${GOPATH}/src/${GO_PROJECT}/
- cd ${GOPATH}/src/${GO_PROJECT}
- env="root:rootroot@tcp(localhost:3306)/TESTDB"
test:
stage: test
services:
- mysql:5.7
variables:
# Configure mysql environment variables (https://hub.docker.com/_/mysql/)
# MYSQL_DATABASE: mydb
MYSQL_ROOT_PASSWORD: rootroot
script:
# Run all tests
go test ./...
build:
stage: build
script:
# Compile and name the binary as `hello`
- go build -o alltools
- pwd
- ls -l alltools
# Execute the binary
- ./alltools
# Move to gitlab build directory
- mv ./alltools ${CI_PROJECT_DIR}
artifacts:
paths:
- ./alltools我的go应用程序中也有一个测试,它在我的开发机器上运行得很好,正如您在上面看到的,我在gitlab-ci.yml文件中设置和环境变量(这与我的dev环境相匹配)。
但是当我运行我的管道时我会得到以下错误..。
$ env="root:rootroot@tcp(localhost:3306)/TESTDB“$ go测试/.? 所有工具都没有测试文件?alltools/BBData无测试文件拨号tcp 127.0.0.1:3306: getsockopt:连接被拒绝
是否需要更改gitlab-ci.yml文件中的环境变量?
发布于 2019-06-27 15:54:40
正如Seddik已经指出的,localhost不是MySQL服务器将要监听的主机;它将以mysql的名称可用。
此外,命令env="root:rootroot@tcp(localhost:3306)/TESTDB"在shell中设置一个局部变量。它不影响环境变量。
设置环境变量
export局部变量variables字典go test命令设置变量:variables:
# Set your variable here for all jobs ...
env: root:rootroot@tcp(mysql:3306)/TESTDB
before_script:
# ... or export it here ...
- export env=root:rootroot@tcp(mysql:3306)/TESTDB
test:
services:
- mysql:5.7
variables:
# ... or set it here for this job only ...
env: root:rootroot@tcp(mysql:3306)/TESTDB
script:
# ... or set it here for the go command only
- env=root:rootroot@tcp(mysql:3306)/TESTDB go test ./...发布于 2019-06-27 15:11:25
你应该使用:
mysql
而不是:
本地主机
https://stackoverflow.com/questions/56793930
复制相似问题