This would have been more easier using a groovy script (ie) Scripted pipeline.
However there is a still a way where you could include it in your declarative pipeline syntax.
You could probably add the "script" step in your Declarative pipeline code in the jenkins file.
The script step takes a block of scripted pipeline and executes that in the Declarative Pipeline.
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('-----') {
steps {
echo '---'
--------------
script {
// Here write your groovy syntax that would extract the substring
}
}
}
}
}
You could try this syntax:
String stringParser(String inputString) {
inputString.split("_")[0]
}
Try adding this snippet in the script section of your declarative jenkinsfile.
Hope this helps!