Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 934
Kingalione Avatar asked Mar 11 '15 13:03

Kingalione


People also ask

How do I pass a Git branch as parameter in Jenkins?

If you want to be able to dynamically give a Git branch to use in a Jenkins build then you'll need to do a couple of things. Then, in your Pipeline configuration, under Branches to build, add your parameter name inside the Branch Specifier box, surrounded by ${} . Jenkins will expand your variable when the job runs.

How do I use Jenkins Git plugin?

How does Jenkins integrate with Git? Go to Jenkins dashboard, click on “Manage Jenkins.” Now follow these steps- Manage Plugins -> 'Available' tab -> Enter Git in search bar and filter -> Install required plugin. After the installation, all you need to do is click on “Configure System” and go to the 'GitHub' section.

How do I list Git branches dynamically in Jenkins pipeline job?

click the Build the Job -> Build History ->Console OutPut -> It will Prompt for Input pass the Branch Name . Above Screen shot which Depicts the dynamically displaying the branches from Git Repository . Option 2: Install Active Choices Plugin and need the groovy script to get the list of branches .

How do I check my Git Jenkins plugin?

Go to “Manage Jenkins>>Manage Plugins”, open the “Available” tab and search for “Git plugin”, click on install button wait until the installation is done.


2 Answers

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.

like image 198
Jonathan Vanderick Avatar answered Oct 22 '22 19:10

Jonathan Vanderick


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
like image 38
andreas caternberg Avatar answered Oct 22 '22 17:10

andreas caternberg