0

I have following Makefile target defined:

.PHONY: docker-build
docker-build:
    # Build Docker image
    docker build \
    --squash \
    ...
    -t $(DOCKER_IMAGE):$(DOCKER_TAG) .

output:
    @echo Docker Image: $(DOCKER_IMAGE):$(DOCKER_TAG)

I need to use the variables DOCKER_IMAGE and DOCKER_TAG as input for another script to run right after the make docker-build.

Do you have any idea how to do it? Thanks in advance.

I have tried many ways but can't get the output from Makefile to environment variables or even just to terminal.

3
  • Did you check this: stackoverflow.com/questions/16645340/… Commented Mar 12, 2020 at 12:45
  • You could A) add the output commands to the docker-build recipe, B) write the variables to a file which the output script -- or the output rule -- could read, or C) have the docker-build rule optionally call the output rule. Does any of those options appeal? Commented Mar 12, 2020 at 18:59
  • Just to elaborate on Beta's comment: it's not possible for the makefile to put environment variables into the shell that invoked make. This has nothing to do with make or makefiles. This is a fundamental feature of all POSIX programs: a program inherits its environment from its parent, and a program can never modify its parent's environment. So, the shell is a program, it invokes make (another program), and it's not possible for the child (make) to modify the environment of the parent (shell). Can't be done. Commented Mar 12, 2020 at 23:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.