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.

1
  • use call function to expand the variable. Commented Mar 1, 2021 at 8:11

1 Answer 1

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)) 
1
  • thank you for the quick response and explanation - that worked. Commented Jun 5, 2019 at 14:54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.