Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I update Jira custom field via REST api

Moshe Hajaj May 1, 2012

In the documentation, I can see that I can only query existing values (GET method).

I need to update "Build number" field (single select list) when official build is sent to QA, via Jenkins/Hudson.

What is the best way to do that?

CLARIFICATION:

I think I didn't explain my use-case clearly enough - I don't need to update specific issue with an existing value in the select list. I need to add new value to the field itself, i.e. I need to update the meta-data. Just like Admin will do from the Administration panel > Custom fields > configure > Edit options.

This way next time a new bug would need to be created the new entry in this field, "Build number", will already be available.

The scenario is this:

  1. We create daily official build.
  2. Add this build number to the "build number" values. Not to any specific issue, but to the field values.
  3. A few days later, when this build reaches QA, someone might open a new bug if he tested system installed with this build number (created in #1).

Is this possible?

16 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

7 votes
Answer accepted
Vishal Gautam February 18, 2014

Followed this tutorial: https://developer.atlassian.com/display/DOCS/Developing+a+REST+Service+Plugin<br< a="">>
Added following method to the Rest Resource class (MyRestResrouce.java in the tutorial).

/**
 * This method is to be used whenever a new option is to be added to a custom field. It will add it to the top of the list.
 * @param fieldId - custom field id, e.g,. customfield_10000
 * @param optionVal - option value, e.g,. 4.1r1.24.67643_70
 * @return
 */
@GET
@AnonymousAllowed
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/addOptionsToCustomField")
public Response addOptionToCustomField(@QueryParam("fieldId") String fieldId, @QueryParam("optionVal") String optionVal)
{
	CustomFieldManager customFldMgr = ComponentAccessor.getCustomFieldManager();
	OptionsManager optionsManager = ComponentAccessor.getComponentOfType(OptionsManager.class);
	
	if (fieldId == null || fieldId.trim().equals("")) {
		return Response.ok(new ZRestResourceModel("default","Missing custom field id")).build();
	}
	
	//error checking code snipped
	
	CustomField customField = customFldMgr.getCustomFieldObject(fieldId);
	//error checking code snipped
	
	List&lt;FieldConfigScheme&gt; schemes = customField.getConfigurationSchemes();
	if (schemes != null &amp;&amp; !schemes.isEmpty()) {
		FieldConfigScheme sc = schemes.get(0);
		MultiMap configs = sc.getConfigsByConfig();
		if (configs != null &amp;&amp; !configs.isEmpty()) {
			FieldConfig config = (FieldConfig) configs.keySet().iterator().next();
			Options ops = optionsManager.getOptions(config);
			if(ops != null &amp;&amp; ops.getOptionForValue(optionVal, null) != null)
				return Response.ok(... snipped
			Option op = optionsManager.createOption(config, null,
					new Long(1), 
					optionVal);         
			ops = optionsManager.getOptions(config); 
			ops.moveToStartSequence(op);
		}
	}
	return Response.ok(new ZRestResourceModel("default","SUCCESS")).build();
}

4 votes
Danilo Conrad
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2015

This is not possible in JIRA out of the box, and the feature request below was raised for this:

A simple alternative which does not require development knowledge is to use the third party plugin (free) JIRA Customfield Editor:

3 votes
StephanS
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 17, 2013

As I understand it's not about updating an issue but about adding a value to an existing (cascading) select list / dropdown (e.g. "build number").

I'm interested in adding new entries to a (cascading) select / dropdown as well as in updating (the spelling of) existing values.

Example with (pseudo) jelly:

<!-- select field to be updated -->
<jira:updateCustomField fieldName="My Cascading Select Field" description="A really good description" > <!-- add a new entry with sub-entries -->
<jira:AddCustomFieldSelectValue value="Main Option 1"> <jira:AddCustomFieldSelectValue value="Option 1.1"/> <jira:AddCustomFieldSelectValue value="Option 1.2"/> </jira:AddCustomFieldSelectValue> <!-- change the text of an existing main entry -->
<jira:UpdateCustomFieldSelectValue value="Main Option 2" newValue="Preferred Main Option 2"> <!-- update text of an existing sub-entry -->
<jira:UpdateCustomFieldSelectValue value="Option 2.1">Option 2.1 alpha</jira:UpdateCustomFieldSelectValue> <!-- add 2 new sub-entries -->
<jira:AddCustomFieldSelectValue value="Option 2.2"/> <jira:AddCustomFieldSelectValue value="Option 2.3"/> </jira:UpdateCustomFieldSelectValue> </jira:UpdateCustomField>

Vishal Gautam June 25, 2013

Did you get any solution for this? We have an exact same requirement where we want to automate adding build numbers to one of JIRA's custom field available options.

2 votes
Vishal Gautam June 25, 2013

Did you get any solution for this? We have an exact same requirement where we want to automate adding build numbers to one of JIRA's custom field available options.

1 vote
kc_ray February 18, 2014

Is this question ever likely to get an answer from someone @ Atlassian??

The whole add a "build ID" from a CI system seems fundamental

From the API point of view, I guess the complexity is knowing which context to update the field list in. There's no link to the context from the editmeta info

Well, that and the REST api CustomFieldOption just having a SET operator, not and ADD. Maybe access the DB directly is the only opiton, if Atlassian don't want to update the API to allow this.

I guess Atlassian open up the Version field via REST, just not custom field lists. Shame that our team don't want their Version list polluted with all the CI incremental builds...

1 vote
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2012

setFieldValue action from JIRA Command Line Interface is a simple way to do this.

Aaron Gabow
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 17, 2015

Just for reference to people who stumble across this comment, I think Bob misunderstood the OP's question. setFieldValue will only work with values that already exist in the system (at least from my testing).

1 vote
Dieter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2012

I recommend you read this tutorial since updating is sometimes confusing for starters.

Please check this tutorial https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Edit+issues

and this one for an example how to set a select list value:

https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue#JIRARESTAPIExample-CreateIssue-SelectList

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 7, 2016

No.  That's a type-2 plugin which you can't install on Cloud.

0 votes
Srinivasaraju Vysyaraju October 6, 2016

Will the same REST Service Plugin work for JIRA Cloud?

0 votes
Vishal Gautam May 14, 2014

Code is shared in the answer post below.

0 votes
ranjithkumar balasubramanian May 12, 2014

Hi vishal-gautam,

We have also the same requirement.Can you please share the info/code that how you achieved this. Million thanks in advance

0 votes
kc_ray February 18, 2014

Hi Vishal,

I would be VERY interested in how you have achieved this, as that is exactly the functionality our QA/SW team would like :-) I'm sure many happy watchers on this thread would be too..put it up on github!

0 votes
Vishal Gautam February 18, 2014

Actually I ended up writing a REST plugin for this and now our QA team uses a simple script that makes a REST call to add a new build number, which is a custom field of single select list type. If anyone is interested, I can share the code.

0 votes
kc_ray February 18, 2014

Thanks for the tip re: forgetting a SQL hack :) Understood!

Maybe it's time to learn about writing a plugin, to add to my recently acquired REST+JSON expertise. I'm, rolling ot Jira to our enterprise, so a nice auto-populated build list would be great, but it looks like being beyond a simple solution.

As an aside to the OP, I've decided to make the build ref a text field for the testers to fill in, rather than a drop down. Our CI system will update the issues with the relevant build/commit data - just need the fleshy components to make sure they're entering the correct info in the first place.

Got to say the Jira REST api makes updating issues pretty simple, much easier than the Rational/IBM tools were were using.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 18, 2014

Possibly not. They lurk here, they do answer, but they're in no way bound to.

You might want to raise it as a feature request at jira.atlassian.com, although I suspect that they already have an issue for expanding REST functions like this.

(As an aside, please forget you even thought of "access the DB directly", you'll break Jira. You must use the API one way or another)

dave
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 1, 2017

I wouldn't stress too much about that actually. I logged all the SQL queries Jira makes when updating an issue via the web interface, and updating a custom value is quite trivial, and nothing breaks.

It doesn't show immediately in the web interface as I suspect the list is cached. But just refresh the list of custom options eg by changing the sequence of an option and they'll appear quite happily.

I agree this is not the ideal way to go, but as Jira doesn't provide an API way to do this, and I'm not typing in 400 options by hand - it seems reasonable to me.

0 votes
Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2012

You can of course edit the issue. Refer the doc at http://docs.atlassian.com/jira/REST/latest/#id162347

We used a simple python script to access Jira via REST/SOAP to do a similar requirement from in Jenkins.

Nagaveer January 21, 2014

Hi renjith,

I can able to update issue if option is already available in cascade select field. But How to add options to cascade select field through rest api?

Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2014

You can't. Either you need to implement your own API or automate the addition using direct HTTP POST requests. Do a live monitoring of the http requested being sent out by the browser (Live HTTP headers in Firefox) and check how an option is getting added while doing it using the standard JIRA interface. Once you get that you can mimic the same HTTP requests from your code. Also note you need to mostly atl_token to requests for the server to accept the requests (got a GET first, parse the incoming HTML to get the token and then make the POST request using that token)

Like Nicolas LACOUR likes this

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events