How to insert a LINEBREAK using the CLI -> setFieldValue

Sascha Mareth September 4, 2013

Hello together.

I am using the CLI so set some custom field values and I encounter the problem that I cannot set linebreaks.

I am particularily using the "setFieldValue"-command as in the script below

<PATH TO CLI>/jira --server "http://SERVER" --user "USER" --password "PASSWORD" --action setFieldValue --issue "ISSUE-ID" --field "FIELDNAME" --values "LINE 1 >> HOW TO INSERT NEW LINE HERE << LINE 2" --appendText

I tried a.o. with "\n", "\n ", " \n ","\r\n", "\r\n ", "\\". (All of them just make the charakters in the field, only " \n " brings up an "Exception 1" without any further note.

I have the target field with the "Normal Text Renderer" and with the "Wiki Markup Renderer" configured and editing the field directly (using the Enter Key) successfully creates a linebreak.

Any clue what I have to write there in order to create the linebreak?

Kind regards

Sascha Mareth

7 answers

1 accepted

0 votes
Answer accepted
Sascha Mareth September 10, 2013

I "solved" this by using Ruby with the jira gem to update the custom field, where "\n" is interpreted as new line.

This particular question still is unanswered, but its not more an issue either.

1 vote
Florian Zink September 10, 2013

Hi Sascha,

according to the documentation it should work with " \n "

Some text fields support the automatic conversion of " \n " (blanks are significant) to be replaced with a new line character - example: --description "A multi-line text field: \n # line 1 \n # line 2"

https://bobswift.atlassian.net/wiki/display/JCLI/Documentation#Documentation-setFieldValue

But I see you solved it anyway :)

MB
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.
September 10, 2013

So, the solution was to place the space character before and after the "\n" right?

Sascha Mareth September 11, 2013

Hi.

I saw this also and tried it with and without spaces - but in my case nothing really worked (not even the " \n "-version with spaces before and after), so I switched to another method.

Even if this question is not really answered so far, it is also not an "open issue" anymore, and I am not available the next 2 weeks.

Thank you for all your feedback and suggestions anyways.

0 votes
EfstratiosI April 20, 2015

I am having a similar problem with updating a page with rest, I have tried all the above suggestions but the page appears with no linebreaks nevertheless:

def write_data(auth, html, pageid, title = None):
    info = get_page_info(auth, pageid)
 
    ver = int(info['version']['number']) + 1
 
    ancestors = get_page_ancestors(auth, pageid)
    anc = ancestors[-1]
    del anc['_links']
    del anc['_expandable']
   # del anc['extensions']
 
    if title is not None:
        info['title'] = title
    data = {
        'id' : str(pageid),
        'type' : 'page',
        'title' : info['title'],
        'version' : {'number' : ver},
        'ancestors' : [anc],
        'body'  : {
            'storage' :
            {
                'representation' : 'storage',
                'value' : str(html).replace("[log]","[log]\\\n"),
            }
        }
    }
    data = json.dumps(data)
    url = '{base}/{pageid}'.format(base = BASE_URL, pageid = pageid)
    print(data)
    r = requests.put(
        url,
        data = data,
        auth = auth,
        headers = { 'Content-Type' : 'application/json'}
    )
    r.raise_for_status()
    print("Wrote '%s' version %d" % (info['title'], ver))
    print("URL: %s%d" % (VIEW_URL, pageid))

The print(data) prints the following:

{"id": "118591392", "version": {"number": 26}, "body": {"storage": {"value": "[log]\\\n CLICK on L(1058,443)@S(0)[0,0 1920x1080]\n[log]\\\n

( Ctrl ) TYPE \"n\"\n[log]\\\n CLICK on L(1071,312)@S(0)[0,0 1920x1080]\n[log]\\\n ( Ctrl ) TYPE \"s\"\n", "representation": "storage"}}, "t

ype": "page", "title": "test2", "ancestors": [{"id": "118591369", "type": "page", "title": "test"}]}


And the outcome looks like this:

Screen Shot 2015-04-20 at 15.27.35.png

0 votes
Sascha Mareth September 10, 2013

The "Exception 1" is not reproducable anymore and I did not find other informations where this occured so far.

0 votes
Sascha Mareth September 10, 2013

I "solved" this by using Ruby with the jira gem to update the custom field, where "\n" is interpreted as new line.

This particular question still is unanswered, but its not more an issue either.

0 votes
MB
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.
September 10, 2013

Did you try using octal escape, like "\012"?

Sascha Mareth September 10, 2013

I tried now, but it does not work either -> using the "Enter"-code just makes the field to be finished and the rest ist cut off.

MB
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.
September 10, 2013

You should report this issue to Atlassian, because I believe it's a bug in their CLI.

0 votes
MB
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.
September 10, 2013

Did you try to print the stack trace of the exception to get a bit more info where the error occurs?

Suggest an answer

Log in or Sign up to answer