In a pipeline I run the following script to grab the version property from a gradle project, and then store off the major version in a variable:
// grab version property, split on '-' to remove '-SNAPSHOT', and then tokenize
def versionParts = sh(returnStdout: true, script: "./gradlew properties -q | grep 'version:' | awk '{print \$2}'").split("-")[0].tokenize(".")
// sometimes this is null??
def majorVersion = versionParts[0]
Sometimes, the majorVersion property seems to evaluate to null, but most of the time it seems to work. Are there any kind of limitations or caveats to using pipes inside the sh command like that? It's almost as if it's not running the pipes in the correct order. The strange part is that it had been working...
I know there are other ways I could use to achieve loading the version property, but what I'm more interested in is the behavior around pipes... specifically in the context of it should be avoided, or if there are special considerations that need to be made when using them.