Jenkins doesnt retrieve git references using git parameter plugin

15,239

Solution 1

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.

Solution 2

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
Share:
15,239
Kingalione
Author by

Kingalione

Full stack developer, loves swift and node.js

Updated on June 28, 2022

Comments

  • Kingalione
    Kingalione almost 2 years

    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

  • andreybavt
    andreybavt over 8 years
    can you please share your 0.4.1-SNAPSHOT hpi package?
  • Jonathan Vanderick
    Jonathan Vanderick over 8 years
    I have stored it here drive.google.com/file/d/… This is the very same version I used and tested.
  • Luke
    Luke about 8 years
    This has resolved all my problems @JonathanVanderick THANKS!