Set up database for integration testing with Jenkins in Docker
The console output describes the error:
line 1: docker: not found
The shell script cannot find docker, likely because Docker is not installed on your Jenkins executor. (The Jenkins Docker plugin does not guarantee that Docker will be available to Jenkins-external processes, such as shell scripts.)
Related videos on Youtube
Shihe Zhang
Updated on September 18, 2022Comments
-
Shihe Zhang over 1 year
Background:
I was following Downloading and running Jenkins in Docker to setupJenkins
Server. Used following parameter to runDocker
.docker run \ -u root \ --rm \ -d \ -p 8080:8080 \ -p 50000:50000 \ -v jenkins-data:/var/jenkins_home \ -v /var/run/docker.sock:/var/run/docker.sock \ jenkinsci/blueocean
The build is running successfully, however, when it comes to
Integration Test
stage, aMySQL
database is required.
The plan is Using multiple containers, while myJenkinsfile
is as following:pipeline { agent { docker { image 'maven:3-alpine' args '-v /root/.m2:/root/.m2' } } stages { stage('Build') { when { changeRequest() } steps { sh 'mvn -B -DskipTests clean package' } } stage('Test') { agent { docker { image 'mysql/mysql-server' args '--name some-mysql -e MYSQL_ROOT_PASSWORD=password -d'} } steps { sh 'mvn test -DforkCount=0' sh ''' docker exec some-mysql sh -c 'exec mysql < ./db/dump.sql ''' } post { always { junit 'target/surefire-reports/*.xml' } } } } }
The
./db/dump.sql
is in the same git repository withJenkinsfile
indb
subdirectory.Problem:
[workspace@2] Running shell script + docker inspect -f . mysql/mysql-server /var/jenkins_home/jobs/myproject/branches/master/workspace@2@tmp/durable-77d559d6/script.sh: line 1: docker: not found [Pipeline] sh [workspace@2] Running shell script + docker pull mysql/mysql-server /var/jenkins_home/jobs/myproject/branches/master/workspace@2@tmp/durable-21da0ff2/script.sh: ... line 1: docker: not found ERROR: script returned exit code 127 Finished: FAILURE
Since running as root, the privilege should not be the problem, right? Using Docker with Pipeline provided several solutions, would other solution be much easier to set up the
Integration Test
environment? -
Shihe Zhang almost 6 yearsSo what would be your suggestion?
-
jayhendren almost 6 yearsInstall Docker on your Jenkins executor
-
Shihe Zhang almost 6 yearsIs
agent
docker
part able to handle it? Feel install docker in docker is not a good idea in instinct. -
Shihe Zhang almost 6 yearsI plan to write a
Dockfile
build FROM MySQL and Jenkins would that works?