Having trouble attempting to set a environment variable that uses substring extraction of another environment variable.
pipeline {
agent any
environment {
NODE_BASE_NAME = "ui-node-${GIT_COMMIT:0:6}"
}
stages {
stage ("test") {
steps {
echo "${NODE_BASE_NAME}"
}
}
}
}
Results in
WorkflowScript: 4: expecting '}', found ':' @ line 4, column 49.
NAME = "ui-node-${GIT_COMMIT:0:6}"
The intrinsic method for doing a substring in Groovy is String substring(int beginIndex, int endIndex)
. Therefore, the correct syntax for interpolating your string assigned to NODE_BASE_NAME
with a GIT_COMMIT
substring is:
environment {
NODE_BASE_NAME = "ui-node-${GIT_COMMIT.substring(0, 6)}"
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.