0

I have been trying to get the remove "origin" from branch name in JenkinsFile sh script using

 steps {
                sh """#!/bin/bash 
                echo '${GIT_BRANCH\#*/}'
                """
 }

I have tried replacing it with based on other suggestions but did not succeed.

"${GIT_BRANCH\#*/}" "${GIT_BRANCH#*/}" '${GIT_BRANCH\#*/}' '${GIT_BRANCH#*/}'

All come with error:

WorkflowScript: 80: unexpected char: '#' @ line 80, column 38.
                       echo ${GIT_BRANCH#*/}

or

WorkflowScript: 80: unexpected char: '\' @ line 80, column 38.
                       echo ${GIT_BRANCH\#*/}

Running in Jenkins jenkins/jenkins:2.418 Any hints?

ozimki
  • 75
  • 8
  • Not sure what you are trying to do, but have you tried ${GIT_BRANCH}/#.* – Katu Aug 29 '23 at 09:17
  • I am trying to stip "origin\" from branch name this you do using bash command ${var_name#*/} that would get "b_name" from "origin/b_name" – ozimki Aug 29 '23 at 09:30

1 Answers1

1

Simply do the following.

sh'''
  result=${GIT_BRANCH#*/}
  echo "Result: $result"
'''
ycr
  • 12,828
  • 2
  • 25
  • 45
  • Thanks @ycr . It worked. Found more explanation here if anyone gets same issue: https://stackoverflow.com/questions/39333715/whats-the-difference-between-and-in-terms-of-running-a-shell-script-wit – ozimki Aug 30 '23 at 06:39