Jenkins pipeline + Docker integration I have a CI server which has Jenkins installed in the host it self, and I want to run builds and tests inside Docker containers. Until here it works like it should, but I also want to deploy containers using docker-compose and this should be done in the host, but when I run commands inside the Jenkinsfile, they are ran inside the Docker container used for builds and tests.

pipeline {
agent {
    dockerfile {
        filename "Dockerfile"
    }
}

stages {
    stage("Run unit tests") {
        steps {
            # This is ran inside the Docker container, as expected
            sh "cp environments/.env.build .env"
            sh "vendor/bin/phpunit"
        }
    }

    stage('Deploy to test') {
        when {
            branch "develop"
        }

        steps {
            # This is still ran inside the Docker container, not the host
            sh 'docker-compose up -d'
        }
    }

    stage("Archive") {
        steps {
            # This is ran inside the Docker container, as expected
            sh "zip -r dist.zip ."
        }
    }
}

post {
    always {
        archiveArtifacts artifacts: "dist.zip"
        junit "reports/phpunit.report.xml"
    }
}
}
One way to solve this it to use multiple pipelines. The first pipeline runs the test in docker. When that has been completed, one could call another job

https://jenkins.io/doc/pipeline/steps/pipeline-build-step/

https://support.cloudbees.com/hc/en-us/articles/221400287-How-to-pass-parameter-to-downstream-job-in-Pipeline-job-


node {
    paramAValue = "paramAValue"
    paramBValue = "paramBValue"
    build job: 'downstream-freestyle', parameters: [[$class:  'StringParameterValue', name: 'ParamA', value: paramAValue], [$class:
       'StringParameterValue', name: 'ParamB', value: paramBValue]]
}



that runs docker-compose on Jenkins itself.