title: Checking if Git branch exists from within Jenkins Groovy script
body: <p>Is there any way to check if the Git branch exists in a Jenkins console Groovy script? What i have now is this:</p>
  
  <pre><code>import hudson.model.*
  // For each project
  for(item in Hudson.instance.items) {
    // check that job is not building
    if(!item.isBuilding()) {   
      if (item.scm instanceof hudson.plugins.git.GitSCM) {  
        println("Item name: " + item.name);
        item.scm.repositories.each {
          println("Repo " + it.name);
          it.URIs.each {uri -&gt;
            println("URI: " + uri.toString());
          }
        }
        item.scm.branches.each {
          println("Branch " + it.name);
        }
      }
    }
    else {
      println("Skipping job "+item.name+", currently building")
    }
  }
  </code></pre>
  
  <p>This prints Jenkins job names, repositories and branches, but can i e.g. run a test pull in order to verify branch existence?</p>
  
  <p>At this moment i am not able to install Git commit hooks to record deleted branch names, so have to resort to scheduled branch existence verification using the script.</p>
  
  <p>Thanks!</p>