【发布时间】:2018-02-24 18:33:41
【问题描述】:
我想制作一个 Jenkinsfile 来进行测试并构建我的 Spring Boot Java 应用程序。问题是我的测试需要 Postgres 和 RabbitMQ。
我正在尝试做的事情:
1) 在 docker 中设置 Jenkins
## Run Jenkins Docker :
sudo docker run -d -p 8080:8080 -p 50000:50000 -v /home/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -u root jenkins
Bash into docker container
## Bash into new docker container
docker exec -it {{ontainer_ID}} bash
## Download an install docker as root
curl -sSL https://get.docker.com/ | sh
exit
2) 制作管道:
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean package'
}
}
stage('Test') {
steps {
/* Run some tests which require PostgreSQL */
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
}
}
我的目标是在测试前的阶段添加 postgres 和 rabbit。我找到了这个https://jenkins.io/doc/book/pipeline/docker/ 有一个示例如何运行额外的 docker 图像:
checkout scm
/*
* In order to communicate with the MySQL server, this Pipeline explicitly
* maps the port (`3306`) to a known port on the host machine.
*/
docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw" -p 3306:3306') { c ->
/* Wait until mysql service is up */
sh 'while ! mysqladmin ping -h0.0.0.0 --silent; do sleep 1; done'
/* Run some tests which require MySQL */
sh 'make check'
}
寻找一些可以帮助我设置的经验丰富的开发人员。谢谢。
【问题讨论】:
-
请详细说明实际问题是什么......
-
谢谢大家,我提出了一个更详细的新问题*.com/questions/49004884/…
标签: docker jenkins jenkins-pipeline