我正在嘗試運行以下subst
命令將一個字串替換/var/jenkins_home
為另一個字串/srv/jenkins-slave-1/data
,以便值從HOST_LOG_DIR
更改/var/jenkins_home/workspace/ts_myapp_testing_integration-tests
為
/srv/jenkins-slave-1/data/workspace/ts_myapp_testing_integration-tests
但是當我運行 makefile 目標時,substtest
的值HOST_LOG_FILE
保持不變(請參見螢幕截圖)。
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]
奇怪的是,當我替換$(JENKINS_HOME)
為實際路徑值時/var/jenkins_home
,即
HOST_LOG_DIR := $(subst /var/jenkins_home,$(JENKINS_HOME_HOST_PATH),$(WORKSPACE))
然後它按預期工作,
我需要修復這個問題,以便它可以在沒有硬編碼替換的情況下工作。
答案1
JENKINS_HOME := "/var/jenkins_home"
你應該不是引用 Makefile 中的變數值。這不是 shell,引號沒有任何特殊之處,也不會被刪除。
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))