Comment Can't be Created because the Text is Too Long

    Problem

    Comments cannot be created due to the text being too long.

    Error detail:
    Comment could not be created because null. comment: The entered text is too long. It exceeds the allowed limit of 32767 characters.


    Cause

    By default, JIRA enforces a character limit for fields such as comments and descriptions. This value can be configured from the Advance Settings under General Configuration.

    Solution

    There're 2 possible solutions:

    1. Change the comment size limit of your JIRA. You can do that through the General Configuration -> Advance Settings -> change jira.text.field.character.limit property.
      If you set it to 0 then the size will be unlimited.

      This solution works only for Jira Server. 

      You cannot change the jira.text.field.character.limit on Jira Cloud.

    2. Trim the comment size to a certain limit, you can do that by changing:

      issue.comments = commentHelper.mergeComments(issue, replica)

      to

      issue.comments = commentHelper.mergeComments(issue, replica, {it.body = it.body.take(32700); it})

      The snippet above helps to sync the comment by limiting its size of the comment without information about the


      Or adapt the code such that the length is limited to the maximum available number of characters.

      issue.comments = commentHelper.mergeComments(
          issue,
          replica,
          { comment ->
            def maxCommentLength = 32767
            def template = "[{0}|mailto:{1}]" +
                " commented: \n" +
                "'{quote'}\n" +
                  "{2};\n" +
                "'{quote'}\n"
            def renderedWithoutBody = java.text.MessageFormat.format(
      		template,
      		comment.author.displayName, 
      		comment.author.email, 
      		""
      		)
            def allowedLength = maxCommentLength 
                - renderedWithoutBody.length()
            
            comment.body = java.text.MessageFormat.format(
              template, 
              comment.author.displayName, 
              comment.author.email, 
              comment.body.take(allowedLength)
            )
            comment;
          }
      )