I've been searching for answers to this however I have not been able to find anything other than an old plugin (jira-importers-bitbucket) that is not compatible with Jira 7.X.
I am trying to populate a jira custom filed with the names of the projects within BitBucket. I have a purchased license for Jira Server, BitBucket Server, as well as the ScriptRunner add-on for Jira and BitBucket also fully licensed.
A solid script example would be really cool.
Thanks
-CN
cnodwell Did you get the script ? We are also looking for the same functionality. It will be really helpful if you share the details.
We did.
We combined two behavior scripts 1. for initializing the fields the others to call a rest endpoint script if BitBucket is selected in the Systems listing and then the BitBucket Project List select box is clicked into.
Sorry for the lack of comments in the scripts themselves.
I hope this helps.
The REST Endpoint script.
listBitbucketProjects.groovy
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.json.JsonBuilder
import groovy.json.*
import groovy.json.JsonOutput
import groovy.transform.CompileStatic
import groovy.json.JsonSlurper
import groovy.json.StreamingJsonBuilder;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import org.apache.commons.codec.binary.Base64;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import groovyx.net.http.RESTClient
import org.apache.http.HttpRequest
import org.apache.http.HttpRequestInterceptor
import java.sql.Timestamp
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import org.apache.commons.lang3.StringUtils
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
log.setLevel(Level.DEBUG)
def log = Logger.getLogger("com.onresolve.jira.groovy")
@BaseScript CustomEndpointDelegate delegate
listBitbucketProjects { MultivaluedMap queryParams ->
AtlassianTool tool = new AtlassianTool()
def query = queryParams.getFirst("query") as String
def json = tool.RESTCall("Bitbucket", "/rest/api/1.0/projects?limit=999&query=${URLEncoder.encode(query)}&type=global&status=current")
log.debug(json)
def rt = [
items : json.values.collect { project ->
def html = "${project.key} (${project.name})"
[
value: project.key,
html : html,
label: project.key
]
},
total : json.totalSize,
footer: "Choose Bitbucket project...",
]
return Response.ok(new JsonBuilder(rt).toString()).build()
}
/////end
The behavior script to initialize the fields.
FieldInitalizer.groovy
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import org.apache.log4j.Logger
import org.apache.log4j.Level
import static com.atlassian.jira.issue.IssueFieldConstants.*
@BaseScript FieldBehaviours fieldBehaviours
if (getActionName() != "Create") return;
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
// Custom Fields are initally hidden
getFieldByName("Bitbucket Project List").setHidden(true)
getFieldByName("Bitbucket Project List").setFormValue(null)
getFieldByName("Project").setHidden(true)
getFieldByName("Project Role").setHidden(true)
/////end
The behavior script to call the listener.
BitBucketSystemField.groovy
import com.atlassian.jira.project.Project
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import org.apache.log4j.Logger
import org.apache.log4j.Level
import static com.atlassian.jira.issue.IssueFieldConstants.*
@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
def systemsField = getFieldById(getFieldChanged())
log.debug (systemsField.value)
// Get the custom fields by Name
def bProj = getFieldByName("Bitbucket Project List")
def jProj = getFieldByName("Project")
def jProjRole = getFieldByName("Project Role")
if (systemsField.value.contains("Bitbucket")) {
bProj.setRequired(true)
bProj.setHidden(false)
//Get the Bitbucket Projects
bProj.convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/listBitbucketProjects",
query: true,
formatResponse: "general"
]
])
}
if (!systemsField.value.contains("Bitbucket")) {
bProj.setFormValue(null)
bProj.setRequired(false)
bProj.setHidden(true)
}
/////end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes we did.
A combination of two behaviors and a REST endpoint.
Behavior 1.
FieldInitalize.groovy
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import org.apache.log4j.Logger
import org.apache.log4j.Level
import static com.atlassian.jira.issue.IssueFieldConstants.*
@BaseScript FieldBehaviours fieldBehaviours
if (getActionName() != "Create") return;
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
// Custom Fields are initally hidden
getFieldByName("Bitbucket Project List").setHidden(true)
getFieldByName("Bitbucket Project List").setFormValue(null)
getFieldByName("Project").setHidden(true)
getFieldByName("Project Role").setHidden(true)
getFieldById(ASSIGNEE).setHidden(true)
2. the behavior script to call the rest endpoint script.
BitBucketProjectList.groovy
import com.atlassian.jira.project.Project
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import org.apache.log4j.Logger
import org.apache.log4j.Level
import static com.atlassian.jira.issue.IssueFieldConstants.*
@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
def systemsField = getFieldById(getFieldChanged())
log.debug (systemsField.value)
// Get the custom fields by Name
def bProj = getFieldByName("Bitbucket Project List")
if (systemsField.value.contains("Bitbucket")) {
bProj.setRequired(true)
bProj.setHidden(false)
//Get the Bitbucket Projects
bProj.convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/listBitbucketProjects",
query: true,
formatResponse: "general"
]
])
}
if (!systemsField.value.contains("Bitbucket")) {
bProj.setFormValue(null)
bProj.setRequired(false)
bProj.setHidden(true)
}
The REST endpoint script.
listBitbucketProjects.groovy
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.json.JsonBuilder
import groovy.json.*
import groovy.json.JsonOutput
import groovy.transform.CompileStatic
import groovy.json.JsonSlurper
import groovy.json.StreamingJsonBuilder;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import org.apache.commons.codec.binary.Base64;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import groovyx.net.http.RESTClient
import org.apache.http.HttpRequest
import org.apache.http.HttpRequestInterceptor
import java.sql.Timestamp
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import org.apache.commons.lang3.StringUtils
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
log.setLevel(Level.DEBUG)
def log = Logger.getLogger("com.onresolve.jira.groovy")
@BaseScript CustomEndpointDelegate delegate
listBitbucketProjects { MultivaluedMap queryParams ->
AtlassianTool tool = new AtlassianTool()
def query = queryParams.getFirst("query") as String
def json = tool.RESTCall("Bitbucket", "/rest/api/1.0/projects?limit=999&query=${URLEncoder.encode(query)}&type=global&status=current")
log.debug(json)
def rt = [
items : json.values.collect { project ->
def html = "${project.key} (${project.name})"
[
value: project.key,
html : html,
label: project.key
]
},
total : json.totalSize,
footer: "Choose Bitbucket project...",
]
return Response.ok(new JsonBuilder(rt).toString()).build()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for that duplication, I was having trouble with the auto login and my personal account/work account.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For this solution today in 2022.
I would setup a scriptrunner resource field that would directly run a sql statement against the project field value and populate it into that custom resource field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Craig Nodwell Can u explain in brief on how to implement this. We are trying to do this in our project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@cnodwell, Check out the nFeed plugin. I have used this in the past to connect to the Atlassian DBs to pull project/space names.
pd
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @[deleted]
I am the Product Manager of Elements Connect (previously called nFeed).
Indeed, as @Peter DeWitt said, it's possible to create a Bitbucket project picker with our app.
Here is how:
rest/api/1.0/projects?name=$userInput&limit=20
$.values
{1} ({0})
This is the configuration of a bitbucket project picker with autocomplete. The text typed by the end user in the autocomplete field is used to filter the query. ($userInput variable).
You can adapt this configuration to your needs and explore the Bitbucket configuration here: https://docs.atlassian.com/bitbucket-server/rest/7.3.1/bitbucket-rest.html#idp141
If you have another question about Elements Connect, please contact our support team.
Hope it helps
Regards,
Christophe
Lead Product Manager @ Elements
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.