Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-32244

Environment variable for current branch

    Details

    • Similar Issues:

      Description

      Original reporter A. Klitzing

      I need to know the current branch in generated job (see conditional step) but there is no $BRANCH variable or something like this I can use. $JOB_NAME does not contain only "branch name".

      Please add a $CURRENT_BRANCH or something like this.
      As a work-around I used Envinject plugin with the following groovy script.

      def jobName = currentJob.getName()
      return [BRANCH: "${jobName}"]
      

      It's weird that currentJob.getName() works instead of $JOB_NAME.

        Attachments

          Issue Links

            Activity

            Hide
            aarondmarasco_vsi Aaron D. Marasco added a comment - - edited

            Thank you for the workaround snippet! The git plugin gives you $GIT_BRANCH, but that has an extra "origin/" prefix that I couldn't figure out how to cleanly strip for a parameterized trigger of another job, so came to file this bug.

            Show
            aarondmarasco_vsi Aaron D. Marasco added a comment - - edited Thank you for the workaround snippet! The git plugin gives you $GIT_BRANCH , but that has an extra "origin/" prefix that I couldn't figure out how to cleanly strip for a parameterized trigger of another job, so came to file this bug.
            Hide
            larsmeynberg Lars Meynberg added a comment -

            I read about

            {env.BRANCH_NAME}

            should do the trick. Does that work for you?

            Show
            larsmeynberg Lars Meynberg added a comment - I read about {env.BRANCH_NAME} should do the trick. Does that work for you?

              People

              • Assignee:
                mjdetullio Matthew DeTullio
                Reporter:
                mjdetullio Matthew DeTullio
              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: