詹金斯。并行运行docker容器(声明性)
我想在声明性Jenkins管道中运行两个docker容器,因为我有一个带有后端的容器,它使用Selenium服务器容器进行测试。我知道有一个脚本化的示例,但我想知道是否有声明性选项 脚本化的外观如下所示:詹金斯。并行运行docker容器(声明性),docker,jenkins,Docker,Jenkins,我想在声明性Jenkins管道中运行两个docker容器,因为我有一个带有后端的容器,它使用Selenium服务器容器进行测试。我知道有一个脚本化的示例,但我想知道是否有声明性选项 脚本化的外观如下所示: node { checkout scm docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw"') { c -> docker.image('mysql:5').inside("--link $
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'
}
}
}最后我使用了来自的描述。
withRun
-在主机上执行命令
内部
-容器内部
stage ('Test') {
steps {
// Create network where I will connect all containers
sh 'docker network create test'
script {
//withRun command starts the container and doesn't stop it untill all inside is executed.
//Commands inside are executed on HOST machine
docker.image('selenium/standalone-chrome').withRun("-p 4444:4444 --name=selenium -itd --network=test") {
docker.image("$CONTAINER_NAME:front").withRun("-p 3001:80 --name=front -itd --network=test") {
//We start backend container...
docker.image("$CONTAINER_NAME:back").withRun("-p 8001:80 --name=back -itd --network=test") {
//...and with inside command execute commands *surprise* inside the container
docker.image("$CONTAINER_NAME:back").inside("-itd --network=test") {
//execute commands inside the container
}
}
}
}
}
}
}
您可以并行运行两个阶段,然后分别运行
docker.run
,也可以使用docker compose
。不过,这些方法与伪代码不同。