亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我的管道不允許我通過 golang 連接,盡管它可以在開發環境中運行

我的管道不允許我通過 golang 連接,盡管它可以在開發環境中運行

Go
波斯汪 2023-06-26 17:40:30
我有一個 .gitlab-ci.yml 文件,稍后使用 golang 圖像和 MySql 圖像作為服務......吉拉布-ci.yml...stages:  - test  - build  - artimage: golang:1.9.2  variables:  BIN_NAME: alltools  ARTIFACTS_DIR: artifacts  GO_PROJECT: alltools  GOPATH: /gobefore_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 文件中設置了環境變量(這與我的開發環境匹配)。env="root:rootroot@tcp(localhost:3306)/TESTDB"但是當我運行管道時出現以下錯誤......$ env="root:rootroot@tcp(localhost:3306)/TESTDB" $ 去測試 ./... ?alltools [沒有測試文件] ?alltools/BBData [無測試文件] 撥打 tcp 127.0.0.1:3306: getsockopt: 連接被拒絕我需要更改 gitlab-ci.yml 文件中的環境變量嗎?
查看完整描述

2 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

localhost 不是 MySQL 服務器將偵聽的主機;它是 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 ./...


查看完整回答
反對 回復 2023-06-26
?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

你應該使用:

mysql

代替:

本地主機


查看完整回答
反對 回復 2023-06-26
  • 2 回答
  • 0 關注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號