'Using --env-file in DockerCompose@0 task generates error "variable is not set. Defaulting to a blank string" despite success

I'm using a docker-compose task in a pipeline that looks like this (the environmentfile is a secure file, that is retrieved, successfully, in a previous task):

- task: DockerCompose@0
    inputs:
      azureSubscription: $(azureSubscription)
      azureContainerRegistry: $(azureContainerRegistry)
      additionalDockerComposeFiles: docker-compose.$(environment).yml
      dockerComposeFile: "$(artifactPath)/compose/docker-compose.yml"
      action: "Run a Docker Compose command"
      dockerComposeCommand: "--env-file $(environmentfile.secureFilePath) up"
      projectName: $(Build.Repository.Name)-$(environment)
      arguments: "-d"

A docker-compose file that looks like this (shortened for brevity):

services:
  api:
    image: myapi
    environment:
     - MYVAR=${ENVVAR1}

And a env-file that looks like this (this is the environmentfile secure-file):

ENVVAR1=MyVariable

And the task and pipeline runs successfully (and using the correct env vars) - but spits out this error:

##[error]The ENVVAR1 variable is not set. Defaulting to a blank string.
C:\ProgramData\chocolatey\bin\docker-compose.exe -f D:\deployagent\A1\_work\1\drop\docker-compose.test.yml -f D:\deployagent\A1\.docker-compose.1643613696562.yml -p "API-test" --env-file D:\deployagent\A1\_work\_temp\api.env.test up -d

Can anyone help me get rid of this error - without using the dockerComposeFileArgs parameter in the task - as that defeats the purpose of using the --env-file flag with the securefile.

dockerComposeFileArgs: | 
    ENVVAR1=mysecretvar


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source