Return String After Character in Jenkins

620 Views Asked by At

I'm using shared libraries in groovy. I have this variable which will return : feature/nameofthebranch

def BRANCH = steps.sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()

However I only need the character after the "/" I've tried split and other stuff but doesn't work as I would like to, maybe because I'm clumsy at groovy.

Expected result should be from feature/nameofthebranch to "nameofthebranch"

1

There are 1 best solutions below

0
On

You can do it like this

def BRANCH = steps.sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()

echo "${BRANCH.split('/')[1]}"