Kingalione
Kingalione

Reputation: 4275

Jenkins doesnt retrieve git references using git parameter plugin

Hello I'm trying to configure our jenkins build server to use git branches.

My configuration looks like this:

git plugin

Well if I click on build with parameters I get a empty list like this:

git listing

I have build this project without parameters and it worked. In the Source-Code-Management part I have added our server with the right creditials without ssh. (only username and password)

However I get no git references in the list. I have googled around and found out that this is a common issue if you use ssh but we dont use ssh. I dont want to make a workaround via Extensible Choice Parameter plugin.

So what is the problem here? I cant believe that this is so hard to configure in jenkins...

We use the latest jenkins version and git parameter plugin with the maven id: org.jenkins-ci.tools:git-parameter:0.4.0

Upvotes: 7

Views: 23625

Answers (6)

andreas caternberg
andreas caternberg

Reputation: 11

Here is my solution for bitbucket: (Should work with little modification of the URL for gitlab/github as well)

You can do it with the Bitbucket Rest API and Scriptler: (Here for example with the "tags" endpoint. It works also with other endpoints such as "branches")

  1. Go to Manage Jenkins -> Scriptler -> Add a new Script

    you have to set your values for ORGANISATION, REPOSITORY, USER and PASSWORD. The best way to do is with the "Define script parameters" option in scriptler

```

    String organization="${ORGANISATION}"
    String repository="${REPOSITORY}"
    String endpoint="tags"
    String baseUrl = "https://api.bitbucket.org"
    String version = "1.0"
    // Create authorization header using Base64 encoding
    //HERE YOU CAN GET THE AUTH CREDENTIALS OVER THE CREDENTIALSID INSTEAD 
    String userpass = "${USER}:${PASSWORD}"
    String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
    println basicAuth
    String url = [baseUrl, version, "repositories", organization, repository, endpoint].join("/")
    println "URL " + url
    // Create URL
    URL apiUrl = url.toURL()
    // Open connection
    URLConnection connection = apiUrl.openConnection()
    // Set authorization header
    connection.setRequestProperty("Authorization", basicAuth)
    InputStream inputStream = connection.getInputStream()
    HashMap tags = new groovy.json.JsonSlurper().parseText(inputStream.text)
    inputStream.close()
    Set keys= tags.keySet();
    List<String>  list=new ArrayList<String>()
    keys.each { key ->
        println key
        list.add(key)
    }
    return list

```

  1. Then you should add the "Dynamic Choice Parameter (Scriptler)" parameter to your job and select the scriptler which you have added before. NOTE: You have to install the Dynamic+Parameter+Plug-in before

Upvotes: 1

R C
R C

Reputation: 21

I got same "retrieving git references" but no branches. There were couple of solutions on web.

  1. run chron job which creates list of branches, saves them to filesystem and read it to display.
  2. run groovy script to get list of branches and display.

My solution(which worked for me) was to download sourcecode from github for git-parameter plugin, build plugin and move to jenkins/WEB-INF/plugins. Started showing list of branches available on repo.

steps:

  1. git clone https://github.com/jenkinsci/git-parameter-plugin.git
  2. cd git-parameter-plugin
  3. mvn clean package -DskipTests=true
  4. copy git-parameter.hpi from git-parameter-plugin\target to jenkins/WEB-INF/plugins
  5. restart jenkins.

you should be able to see all branches now.

Upvotes: 0

Jonathan Vanderick
Jonathan Vanderick

Reputation: 166

I had the same problem, and I followed a suggestion found in a discussion: getting the latest version of the plugin (0.4.1-SNAPSHOT) from Github (https://github.com/jenkinsci/git-parameter-plugin), compile it and install it.

That new version of the plugin do work with SSH URL/Credentials in the job's SCM configuration in a Linux environment.

Upvotes: 2

Josh Kehoe
Josh Kehoe

Reputation: 21

I had the same problem of "Retrieving Git references" with no Git tags, but it was not a permission issue. I'm leaving this here in case anyone else stumbles upon this link (first one in Google for the problem) and may have the same issue as me.

When I looked in the Jenkins logs, I saw an error from the Git Parameter plugin for a Java number format error (java.lang.NumberFormatException). This was because I was using the build timestamp to create my tags, which ended up being a very long numerical value. The plugin must recognize it as numeric, then tries to convert it to an int (I assume to do the sort later), but then blows up because it is too long. To fix this, I had to remove all of my tags and change my build to tag with the name of the job plus the build number (For example, DEV-233). After I did that, the list of tags was populating correctly.

Upvotes: 0

DuncanSungWKim
DuncanSungWKim

Reputation: 4134

If you are using Jenkins on Windows, Git Parameter Plug-In 0.4 may not work and keep showing "retrieving Git references".

I believe the reason is that the plug-in doesn't use Jenkins' credential but runs git commands as the system's logged-on user. You can fix it by changing JenKins' Windows service's logged on user to the real person who has logged on and saved the password in the Windows Credentials.

Upvotes: 0

Sergii
Sergii

Reputation: 11

Workaround. Works fine for me. Hope plugin will be fixed soon.

  1. Create new item i.e."git_repo". Add Git repository. Build this project once.
  2. In the project you need branch/tag use, just add "file://" repository with workspace from step one: example (file:///var/lib/jenkins/jobs/git_repo/workspace)

In this case my project can fetch all data i need to build my project.

Upvotes: 0

Related Questions