我目前正在编写一个.gitlab-ci.yml文件来自动化我的应用程序的构建,测试,打包和部署,但构建作业正在通过,但其他工作(测试,部署)是失败。
我的应用程序是一个Springboot Web应用程序,带有一个用于存储数据的Mysql数据库,我使用maven来构建项目。
下面是我的.gitlab-ci.yml文件
before_script:
- echo "Execute scripts which are required to bootstrap the application. !"
after_script:
- echo "Clean up activity can be done here !."
stages:
- build
- test
- package
- deploy
variables:
MAVEN_CLI_OPTS: "--batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
- target/
build:
stage: build
image: maven:latest
script:
- mvn $MAVEN_CLI_OPTS clean compile
test:
stage: test
image: maven:latest
script:
- mvn $MAVEN_CLI_OPTS test
package:
stage: package
image: maven:latest
script:
- mvn $MAVEN_CLI_OPTS package
artifacts:
paths: [target/basecamp-0.0.1.war]
deploy_test:
stage: deploy
script:
- echo "######## To be defined ########"
environment: staging
deploy_prod:
stage: deploy
script:
- echo "######## To be defined ########"
only:
- master
environment: production
我收到的错误如下:
2017-12-23 10:00:33.854 WARN 65 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : maxIdle is larger than maxActive, setting maxIdle to: 50
2017-12-23 10:00:34.567 ERROR 65 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2222)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
你能知道这是什么问题吗?
谢谢, -G。
答案 0 :(得分:1)
找到你的Spring上下文测试并禁用它(例如将其注释掉或在测试类上使用JUnit的@Ignore为你的管道进行新的尝试。文本可能如下所示:
@RunWith(SpringRunner.class)
@SpringBootTest
public class YourApplicationTest {
@Test
public void contextLoads() {
}
}
您的异常是因为抛出,因为在测试期间无法访问您的数据库。可以在此处找到详细说明和一些故障排除:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
答案 1 :(得分:0)
好吧,这有点晚了...但是我假设您没有用于构建过程(集成测试)的MySQL数据库。这就是为什么您收到CommunicationsException的原因。我有同样的问题。我尝试设置一个gitlab-pipeline,它可以执行集成测试(尚不能使用)
这就是我发现的东西