Reputation: 1762
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}"
Upvotes: 3
Views: 4279
Reputation: 28749
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)}"
}
Upvotes: 6