【发布时间】:2018-10-26 09:41:45
【问题描述】:
我正在设置一个 PHP 构建系统,并且需要运行 MySQL 的本地实例来执行测试。目前我正在使用声明性管道语法并使用 docker。是否可以以声明式语法将 MySQL 作为 sidecar 运行?
如果没有其他方法可以运行 MySQL 代理以及自定义 docker 映像并执行迁移?
【问题讨论】:
标签: jenkins continuous-integration jenkins-pipeline
我正在设置一个 PHP 构建系统,并且需要运行 MySQL 的本地实例来执行测试。目前我正在使用声明性管道语法并使用 docker。是否可以以声明式语法将 MySQL 作为 sidecar 运行?
如果没有其他方法可以运行 MySQL 代理以及自定义 docker 映像并执行迁移?
【问题讨论】:
标签: jenkins continuous-integration jenkins-pipeline
目前有no support for sidecar containers in Jenkins declarative pipelines。
您使用脚本化管道as shown in the Jenkins documentation 将 MySQL 作为 sidecar 容器运行:
node {
checkout scm
docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw"') { c ->
docker.image('mysql:5').inside("--link ${c.id}:db") {
/* Wait until mysql service is up */
sh 'while ! mysqladmin ping -hdb --silent; do sleep 1; done'
}
docker.image('centos:7').inside("--link ${c.id}:db") {
/*
* Run some tests which require MySQL, and assume that it is
* available on the host name `db`
*/
sh 'make check'
}
}
}
您可以使用<script> 标签在声明性管道中执行脚本化管道片段:https://jenkins.io/doc/book/pipeline/syntax/#script
【讨论】: