I am setting up a PHP build system and needs to run a local instance of MySQL for executing tests. Currently I am using declarative pipeline syntax and using docker. Is it possible to run MySQL as a sidecar in declarative syntax ?
If not any other method to run MySQL agent along with a custom docker image and execute migrations ?
Currently there is no support for sidecar containers in Jenkins declarative pipelines.
You run MySQL as a sidecar container using scripted pipeline as shown in the Jenkins documentation:
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'
}
}
}
You can execute pieces of scripted pipeline in a declarative pipeline using the <script>
tag: https://jenkins.io/doc/book/pipeline/syntax/#script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With