在GitLab CI上的测试脚本之前执行mysql命令 [英] Execute mysql command before test script on GitLab CI
本文介绍了在GitLab CI上的测试脚本之前执行mysql命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在执行测试脚本之前创建测试数据库.我已经包含了mysql服务,但是我找不到运行mysql命令的方法.
I want to create the test database before my test script executes. I have included the mysql service, but I can't find a way to run mysql command.
我在before-script
中运行mysql ...
,但是它一直在抱怨
I run mysql ...
in before-script
, but it keep complaining
/bin/bash: line 57: mysql: command not found
这是我的.gitlab-ci.yml
↓
image: maven:3.5-jdk-8
services:
- mysql
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
MYSQL_ROOT_PASSWORD: example
cache:
paths:
- .m2/repository
compile:
stage: build
script:
- 'mvn $MAVEN_CLI_OPTS test-compile'
verify:
stage: test
before_script:
- mysql --user=root --password=\"$MYSQL_ROOT_PASSWORD\" --host=mysql < src/main/sql/database.sql
script:
- 'mvn $MAVEN_CLI_OPTS verify'
artifacts:
paths:
- target/*.jar
推荐答案
您正在另一个容器中运行MySQL,作为要连接的服务. maven:3.5-jdk-8
图像不包含您使用mysql
调用的mysql-client
程序包.
You are running MySQL in a different container as a service to connect to. The maven:3.5-jdk-8
image doesn't contain the mysql-client
package you invoke using mysql
.
所以要解决它;在您的before命令中安装mysql-client
:
So to solve it; install the mysql-client
in your before command:
before_script:
- apt-get update -q && apt-get install -qqy --no-install-recommends mysql-client
- mysql --user=root --password=\"$MYSQL_ROOT_PASSWORD\" --host=mysql < src/main/sql/database.sql
这篇关于在GitLab CI上的测试脚本之前执行mysql命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文