0

I am trying to run the following subst command to replace one string /var/jenkins_home with another /srv/jenkins-slave-1/data so that the value in HOST_LOG_DIR changes from /var/jenkins_home/workspace/ts_myapp_testing_integration-tests to /srv/jenkins-slave-1/data/workspace/ts_myapp_testing_integration-tests

but when I run the makefile target substtest the value of HOST_LOG_FILE remains unchanged (please see screenshot).

WORKSPACE               := "/var/jenkins_home/workspace/ts_myapp_testing_integration-tests"
JENKINS_HOME            := "/var/jenkins_home"
JENKINS_HOME_HOST_PATH  := "/srv/jenkins-slave-1/data"
HOST_LOG_DIR            :=  $(subst $(JENKINS_HOME),$(JENKINS_HOME_HOST_PATH),$(WORKSPACE))

.PHONY: substtest, print_env

substtest: print_env

print_env:
    @echo "WORKSPACE is ${WORKSPACE}"
    @echo "JENKINS_HOME is ${JENKINS_HOME}"
    @echo "JENKINS_HOME_HOST_PATH is ${JENKINS_HOME_HOST_PATH}"
    @echo "HOST_LOG_DIR is ${HOST_LOG_DIR}"][1]][1]

enter image description here

The strange thing is when I replace $(JENKINS_HOME) with the actual path value /var/jenkins_home i.e.

HOST_LOG_DIR := $(subst /var/jenkins_home,$(JENKINS_HOME_HOST_PATH),$(WORKSPACE))

then it works as expected,

enter image description here

I need to fix this so that it works without the hard-coded substitution.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
robbie70
  • 183

1 Answers1

2
JENKINS_HOME            := "/var/jenkins_home"

You should not quote the variable values in Makefiles. This is not shell, the quotes are not special in any way and are not removed.

WORKSPACE               := /var/jenkins_home/workspace/ts_myapp_testing_integration-tests
JENKINS_HOME            := /var/jenkins_home
JENKINS_HOME_HOST_PATH  := /srv/jenkins-slave-1/data
HOST_LOG_DIR            :=  $(subst $(JENKINS_HOME),$(JENKINS_HOME_HOST_PATH),$(WORKSPACE))