I am implementing a build system for PHP and need to execute a Build step , 
which needs repository checkout and run composer. Now this is working fine 
inside the docker container. As the next stage, I need to run automated 
test cased written in PHPUnit, which needs MySQL, Redis and Elasticsearch 
installation. Currently I am using CircleCI for the build process and there 
it is just a matter of pulling different docker images and executing 
migrations. I am trying to the same in Jenkins, but as soon as I am out of 
the MySQL stage, the docker container has been removed and so there is no 
point in running migrations. 

How can I run the MySQL sever persitantly so that all the scripts will be 
executed there ?

Or the better approach is to build a Docker container with MySQL, Redis and 
Elasticsearch and then run all the steps there ?

My current Jenkins file looks like the following

pipeline {
 agent any


 stages {
 stage('Build') {
 agent {
 docker {
 image 'cutomname/application:7.1'
 args '-u root:root'
 }
 }
 steps {
 checkout([
 $class: 'GitSCM',
 branches: [[name: '*/master']],
 doGenerateSubmoduleConfigurations: false,
 extensions: [],
 submoduleCfg: [],
 userRemoteConfigs: [
 [credentialsId: 'token', url: '[email protected]:MyCutstomOrg/repository.git'
]]
 ])
 sh 'yum install -y sudo'
 sh 'cp -f .env.circleci .env'
 sh 'chmod 755 ./build/database-migrations.sh'
 sh 'chmod a+rw -R storage'
 sh 'composer install --prefer-dist --no-interaction --no-progress'
 sh 'sudo npm install --progress=false'


 }
 }
 stage('Starting MySQL') {
 agent {
 docker {
 image 'mysql:5.6'
 }
 }
 environment {
 MYSQL_ALLOW_EMPTY_PASSWORD='yes'
    }
 steps {
 sh 'echo MySQL server started successfully'
 }
 }
 stage('Database Migration') {
 steps {
 sh './build/database-migrations.sh'
 }
 }
 }
 }



-- 
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/fd9675e2-c4d6-4239-92ce-e485fa02cd24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to