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

Provide easy access to git branch name in (single branch) Pipeline build

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major Major
    • branch-api-plugin
    • None
    • LTS 2.73.1 (2017-09-13)

      Hello,

      I'm the maintainer of a maven-plugin (https://github.com/ktoso/maven-git-commit-id-plugin ) that exposes certain repository information as properties into the build. A user of of this plugin reported that the branch name is not available with a single branch pipeline build under jenkins. From the plugin perspective we rely (especially for the branch identifier) on the environment properties that are being exposed by the [Git Plugin|https://github.com/ktoso/maven-git-commit-id-plugin ]. In particular we use the GIT_LOCAL_BRANCH or GIT_BRANCH . Unfortunately with Jenkins LTS 2.73.1 (2017-09-13) those environment variables are not available and thus making it impossible to retrieve the branch name.

      Thank you for your time.

       

      Note:

      During my initial debugging I noticed that a user could this get to work when using a parameterized build which is not really beautiful since the parameter used need to be set to GIT_LOCAL_BRANCH or GIT_BRANCH since its then automatically exposed as environment variable (would consider this a dirty hack)...

      pipeline {
          agent any
          parameters {
              string(defaultValue: 'master', description: 'branch', name: 'GIT_BRANCH')
          }
          
          stages {
              stage('Clone sources') {
                  steps {
                      git branch: "${params.GIT_BRANCH}", url: 'https://github.com/ktoso/maven-git-commit-id-plugin.git'
                  }
              }
              
              stage('Build printenv'){
                  steps {
                      sh 'printenv'
                  }
              }
          }
      }
      

       
      Original issue: https://github.com/ktoso/maven-git-commit-id-plugin/issues/325

          [JENKINS-47226] Provide easy access to git branch name in (single branch) Pipeline build

          S L created issue -
          S L made changes -
          Link New: This issue is related to JENKINS-30252 [ JENKINS-30252 ]
          S L made changes -
          Link New: This issue is related to JENKINS-26100 [ JENKINS-26100 ]
          S L made changes -
          Description Original: Hello,

          I'm the maintainer of a maven-plugin ([https://github.com/ktoso/maven-git-commit-id-plugin] ) that exposes certain repository information as properties into the build. A user of of this plugin reported that the branch name is not available with a single branch pipeline build under jenkins. From the plugin perspective we rely (especially for the branch identifier) on the environment properties that are being exposed by the [Git Plugin|[https://github.com/ktoso/maven-git-commit-id-plugin] ]. In particular we use the {{GIT_LOCAL_BRANCH}} or {{GIT_BRANCH}} . Unfortunately with Jenkins LTS 2.73.1 (2017-09-13) those environment variables are not available and thus making it impossible to retrieve the branch name.

          Thank you for your time.

           

          Note:

          During my initial debugging I noticed that a user could this get to work when using a parameterized build which is not really beautiful since the parameter used need to be set to {{GIT_LOCAL_BRANCH}} or {{GIT_BRANCH}} since its then automatically exposed as environment variable (would consider this a dirty hack)...
          {code:java}
          pipeline {
              agent any
              parameters {
                  string(defaultValue: 'master', description: 'branch', name: 'GIT_BRANCH')
              }
              
              stages {
                  stage('Clone sources') {
                      steps {
                          git branch: "${params.GIT_BRANCH}", url: 'https://github.com/ktoso/maven-git-commit-id-plugin.git'
                      }
                  }
                  
                  stage('Build printenv'){
                      steps {
                          sh 'printenv'
                      }
                  }
              }
          }
          {code}
           
          New: Hello,

          I'm the maintainer of a maven-plugin ([https://github.com/ktoso/maven-git-commit-id-plugin] ) that exposes certain repository information as properties into the build. A user of of this plugin reported that the branch name is not available with a single branch pipeline build under jenkins. From the plugin perspective we rely (especially for the branch identifier) on the environment properties that are being exposed by the [Git Plugin|[https://github.com/ktoso/maven-git-commit-id-plugin] ]. In particular we use the {{GIT_LOCAL_BRANCH}} or {{GIT_BRANCH}} . Unfortunately with Jenkins LTS 2.73.1 (2017-09-13) those environment variables are not available and thus making it impossible to retrieve the branch name.

          Thank you for your time.

           

          Note:

          During my initial debugging I noticed that a user could this get to work when using a parameterized build which is not really beautiful since the parameter used need to be set to {{GIT_LOCAL_BRANCH}} or {{GIT_BRANCH}} since its then automatically exposed as environment variable (would consider this a dirty hack)...
          {code:java}
          pipeline {
              agent any
              parameters {
                  string(defaultValue: 'master', description: 'branch', name: 'GIT_BRANCH')
              }
              
              stages {
                  stage('Clone sources') {
                      steps {
                          git branch: "${params.GIT_BRANCH}", url: 'https://github.com/ktoso/maven-git-commit-id-plugin.git'
                      }
                  }
                  
                  stage('Build printenv'){
                      steps {
                          sh 'printenv'
                      }
                  }
              }
          }
          {code}
           
          Original issue: https://github.com/ktoso/maven-git-commit-id-plugin/issues/325
          Stephen Connolly made changes -
          Assignee Original: Stephen Connolly [ stephenconnolly ]
          Bruce made changes -
          Assignee New: Bruce [ bruce_edge ]
          Bruce made changes -
          Assignee Original: Bruce [ bruce_edge ]

            Unassigned Unassigned
            thesnoozer S L
            Votes:
            10 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: