title: Jenkins pipeline - Environment variable for docker-compose
body: <p>I'm trying to use <code>docker-compose</code> with environment variable for the image name set by the <code>Jenkinsfile</code> but it is not working.</p>
  
  <p>I have a <code>Jenkinsfile</code> containing</p>
  
  <pre class="lang-groovy prettyprint-override"><code>node() {
  
    stage('Checkout') {
      cleanWs()
      git credentialsId: 'xxx', url: 'ssh://git@...'
    }
  
    stage('Build') {
      withMaven(maven: 'maven-3.5.3') {
        sh 'mvn clean package'
        def pom = readMavenPom file:'pom.xml'
        JAR_FILE = pom.artifactId + "-" + pom.version + ".jar"
        JAR_VERSION = pom.version
      }
    }
  
    stage('Build Docker Image') {
      echo "Docker Build ..."
      docker.withTool('docker') {
        app = docker.build("microservices/my-service:${JAR_VERSION}","--build-arg JAR_FILE=${JAR_FILE} .")
      }
    }
  
    stage('Running Docker Container') {
      echo "Docker Run ..."
      withEnv(['VERSION=1.0.0']) {
        docker.withTool('docker') {
          sh "docker-compose rm -f -s -v"
          sh "docker-compose up -d"
        }
      }
      cleanWs()
    }
  }
  </code></pre>
  
  <p>And a <code>docker-compose.yml</code> like</p>
  
  <pre class="lang-yaml prettyprint-override"><code>version: '3.6'
  
  services:
  
      my-service:
          image: microservices/my-service:${VERSION}
          container_name: my-service
          ...
  </code></pre>
  
  <p>Everything is working fine excepts that the last stage is not using my environment variable.</p>
  
  <pre><code>Docker Run ...
  [Pipeline] withEnv
  [Pipeline] {
  [Pipeline] tool
  
  [Pipeline] withEnv
  [Pipeline] {
  [Pipeline] sh
  
  [my-service] Running shell script
  + docker-compose rm -f -s -v
  The VERSION variable is not set. Defaulting to a blank string.
  </code></pre>