Creating Jira ReleaseNotes from a Jenkins job

I got an interesting task from my customer. He wanted me to generate a ReleaseNotes.html file automatically from a Jenkins job's build.

First, I tried to make the Jira's plugin Generate Release Notes feature to work. The Jira plugin's wiki is quite strait forward but it did not work for me.

After consulting with one of my team mates and trying some things we have found out that the problem only occures if the build is running on windows slaves.

On Linux slave, I have echoed the JiraReleaseNotes parameter and got one long line with all the data. It was some progress but still wasn't the end of my task. I still had to create a formatted html out of this long line.

Then I started to try and parse this long line in shell script with no success. When googling on "split string" in a shell script, the only way is using the "tr" command but the tr command only replaces charachters in string and that wasn't enough to split the lines because running in a loop over the splitted lines resulted in splitting the long line into spaces. It means that every space became a new line. 

I then thought of another sulotion that might work. Redirect each tr command to a file and then parse the file line by line. Surprisingly it did work (Don't ask me why because I have no idea). My script consisted of 4 "while read line" loops but it works :-)

Here is the script:

  retVal="false"

  contains() {
    string="$1"
    substring="$2"
    if test "${string#*$substring}" != "$string"
    then
        retVal="true"   # $substring is in $string
    else
        retVal="false"    # $substring is not in $string
    fi
  }

 # JiraReleaseNotes is the environment variable that holds the long line of issues

  echo $JiraReleaseNotes > 1.txt

  if [ -f 2.txt ]
  then
    rm -f 2.txt
  fi
  while read LINE
  do
        echo "$LINE" | tr "#" "\n" > 2.txt
  done < 1.txt

  if [ -f 3.txt ]
  then
    rm -f 3.txt
  fi
  while read LINE
  do
        echo "$LINE" | tr "[" "\n" >> 3.txt
  done < 2.txt

  if [ -f 4.txt ]
  then
    rm -f 4.txt
  fi
  while read LINE
  do
        echo "$LINE" | tr "]" "\n" >> 4.txt
  done < 3.txt

 # APP_VERSION is the Jira version of the APP being generated from the Jira Release Number Parameter

  echo "        Release Notes - Applications - APP - Version ${APP_VERSION}" > ReleaseNotes.html
  while read LINE
  do
        contains "$LINE" "Bug"
        ret1=$retVal
        contains "$LINE" "Story"
        ret2=$retVal

        # Project is the project in the Jira
        contains "$LINE" "PROJECT-"
        ret3=$retVal
        if [ $ret1 == "true" -o $ret2 == "true" ]
        then
          echo "</ul>" >> ReleaseNotes.html
          echo "<h2>        $LINE" >> ReleaseNotes.html
          echo "</h2>" >> ReleaseNotes.html
          echo "<ul>" >> ReleaseNotes.html
        elif [ $ret3 == "true" ]
        then

          # URL is the address of your Jira server
          echo -n "<li>[<a href='http://URL:8080/browse/$LINE'>$LINE</a>] -         " >> ReleaseNotes.html
        else
          echo $LINE >> ReleaseNotes.html
          echo "</li>" >> ReleaseNotes.html
        fi
  done < 4.txt
  echo "</ul>" >> ReleaseNotes.html

 

I can't tell if this script will work for any kind of Jira input or Jira version and I'm not sure if it'll fit the HTML format that you need but I think that it is a good start.

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com