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)}"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With