Hi,
I simply use two *sh* steps, one to start the database and the other to
launch the tests.
More or less like this:
node () {
> // Run mysql
> def mysqlOpts = "..."
> sh "docker --rm -d ${mysqlOpts} mysql"
>
> timeout(time: 120, unit: 'SECONDS') {
> waitUntil {
> // Wait until a prepared select returns expected result
> def expected = 50
> def current = sh(script: "...", returnStdout: true).trim()
> return (current == expected)
> }
> }
> // Launch tests
> sh "docker --rm ...."
> }
>
El lunes, 30 de octubre de 2017, 10:57:16 (UTC+1), ysqi escribió:
>
> hi,all,
>
> I want to run my unit test (database) with mysql docker ,but Jenkins
> run failed. Can you help me, thanks a lot!
>
> 1. Is the Pipeline script correct?
>
> 2. My Jenkins server installed docker and docker image
> (ysqi/gcodesharp:go1.9, mysql:5.6)
>
> 3. Error info
>
> Failed to parse docker version. Please note there is a minimum docker
> version requirement of v1.7.
>
> Jenkins does not seem to be running inside a container
>
>
> *Docker version*
>
> Client:
>
> Version: 17.09.0-ce
>
> API version: 1.32
>
> Go version: go1.8.3
>
> Git commit: afdb6d4
>
> Built: Tue Sep 26 22:41:23 2017
>
> OS/Arch: linux/amd64
>
>
>
> Server:
>
> Version: 17.09.0-ce
>
> API version: 1.32 (minimum version 1.12)
>
> Go version: go1.8.3
>
> Git commit: afdb6d4
>
> Built: Tue Sep 26 22:42:49 2017
>
> OS/Arch: linux/amd64
>
> Experimental: false
>
>
> *Pipeline Script:*
>
> pipeline {
>
> agent {
>
> docker {
>
> image 'ysqi/gcodesharp:go1.9'
>
> args "--user root"
>
> }
>
> }
>
> stages{
>
> stage("work"){
>
> steps{
>
> withDockerContainer(args: '-e
> MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=nerthusTest -e
> MYSQL_USER=cnts -e MYSQL_PASSWORD=pwd -p 3306:3306', image: 'mysql:5.6') {
>
> sh "go version"
>
> sh "mysql -h localhost -u cnts -pwd nerthusTest"
>
>
>
> }
>
> }
>
> }
>
> }
>
>
>
> }
>
> *Output:*
>
> [Pipeline] node
>
> Running on master in /var/lib/jenkins/workspace/TestOne
>
> [Pipeline] {
>
> [Pipeline] stage
>
> [Pipeline] { (Declarative: Agent Setup)
>
> [Pipeline] sh
>
> [TestOne] Running shell script
>
> + docker pull ysqi/gcodesharp:go1.9
>
> go1.9: Pulling from ysqi/gcodesharp
>
> Digest:
> sha256:0203f84a55c0e5289966f99137bf126a88fc1b53032aa77d0b4314cd8ca03ed5
>
> Status: Image is up to date for ysqi/gcodesharp:go1.9
>
> [Pipeline] }
>
> [Pipeline] // stage
>
> [Pipeline] sh
>
> [TestOne] Running shell script
>
> + docker inspect -f . ysqi/gcodesharp:go1.9
>
> .
>
> [Pipeline] withDockerContainer
>
> Jenkins does not seem to be running inside a container
>
> $ docker run -t -d -u 996:994 --user root …… --entrypoint cat
> ysqi/gcodesharp:go1.9
>
> [Pipeline] {
>
> [Pipeline] stage
>
> [Pipeline] { (work)
>
> [Pipeline] withDockerContainer
>
> ERROR: Failed to parse docker version. Please note there is a minimum
> docker version requirement of v1.7.
>
> Jenkins does not seem to be running inside a container
>
> $ docker exec
> f27addbc86cbd2b1c6561ece4a932b8ef46dd58e86816698a8d5e8006e49a903 env ……
> --entrypoint cat mysql:5.6
>
> [Pipeline] // withDockerContainer
>
> [Pipeline] }
>
> [Pipeline] // stage
>
> [Pipeline] }
>
> $ docker stop --time=1
> f27addbc86cbd2b1c6561ece4a932b8ef46dd58e86816698a8d5e8006e49a903
>
> $ docker rm -f
> f27addbc86cbd2b1c6561ece4a932b8ef46dd58e86816698a8d5e8006e49a903
>
> [Pipeline] // withDockerContainer
>
> [Pipeline] }
>
> [Pipeline] // node
>
> [Pipeline] End of Pipeline
>
> java.io.IOException: Failed to run image 'mysql:5.6'. Error: env:
> 'docker': No such file or directory
>
> ……
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/0d50d1ad-b778-4e2a-a5cc-df0894ca82a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.