Hello I'm trying to configure our jenkins build server to use git branches.
My configuration looks like this:
Well if I click on build with parameters I get a empty list like this:
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
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 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.
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 .
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.
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.
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")
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
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With