How do environment variables work when a Docker container builds itself?

Viewed 41

I'm trying to update an environment variable for a Docker image The image builds like this in Jenkins:

insideNode { // executed inside the container docker-compose is building
  withEnv(['COMPOSE_OPTIONS=-e http_proxy -e https_proxy -e no_proxy']) {
    sh """
      export http_proxy=${env.http_proxy}
      export https_proxy=${env.https_proxy}
      export no_proxy=${env.no_proxy}
      VERSION=${project.version} docker-compose --file docker-compose.yml node-container
    """
  }
}

The insideNode closure is executed inside the Docker container I'm building - so it uses itself to build a new version of itself. I'm trying to update those proxy variables, which you can see are drawn from the environment (the Jenkins container originally, but now its own container).

If I update the environment variables in the overall Jenkins environment, do they flow down to the container build here? I would assume that the closure would be using the container's own environment, which means you can't really update them since they need to be updated, to use the updated values, so it becomes a cyclical dependency. So in this scenario, how would overwrite those env vars?

0 Answers
Related