How to populate Jenkinsfile parameter value properly in docker-compose

Hi Stars,
I have parameter(string) in Jenkins files with the default container image tag/version and also have config.env files to pass the same parameter version.
Now, in my docker-compose file, I put the parameter string but when running in local using the Makefile; it showing me <::invalid reference format> when downloading the image. But things are working when I used the JenkinsUI with the default container image.

Example: here is my sample file structure of my repo

  1. docker-compose contains:
version: '3'
services:
 deploy: 
    image: test_repo/test:${image_tag}
    env_file: .env

  1. config.env:
    image_tag
  2. Jenkinsfile:
pipeline{
  parameters{
      string(name: 'image_tag', defaultValue: '1')
     }
stage ('Override env variable') {
  steps {
     script {
        env.image_tag= "${image_tag}"
}

Execute from local:- docker-compose run --rm deploy
Error: no Such image: test/:: invalid reference format

But from UI, it working correctly by passing the defaultValue to the docker

hi @shekhar84 can you update your docker-compose section? the intending isn’t super clear

I’m not sure how your expecting the parameter to get populated to docker-compose. the parameters should create an env variable called $image_tag

Thanks @halkeye for quickly come back.
I updated the Jenkins file just as sample where overriding the env variable. All our variable is passing correctly except the image tag. From the jenkins file itself, we are calling the number of scripts and instruction is define in Makefile.

okay you shouldn’t need the env.image_tag stage, the parameters should already take care of that.

I recommend adding debugging to figure out whats going on. Right before your sh(“docker-compose run”) add sh(“docker-compose config”) and sh(“printenv”)

Yeah it was not working with the the variable override…so thought that try this as well.
Not sure the docker-compose version has some issue where the Jenkins host are running.

FWIW, I just tried it and it does work from the docker-compose side, but it looks like env variable image_tag is not being set. Not as familiar with declarative, but maybe before running docker-compose you can do what @halkeye suggested and check your variable. You can also do:
sh("image_tag=${image_tag} docker_compose ...") to make sure the variable is set. Also, you may need to remove image_tag from the .env file, it may be confusing things