Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-51106

Empty BufferedReader is returned if we use Java API of Timestamper plug-in without using appendLog param

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • timestamper-plugin
    • None

      Based on the given documentation, I have tried to use Timestamper Java API to access the build log including the plain timestamps. 

      BufferedReader reader = TimestamperAPI.get().read(currentBuild,"time=HH:mm:ss")

      But, I am receiving an empty buffer.

      After checking the out timestamper plug-in code and debugging the code, I understood that we need to pass "appendLog" param also to get the proper BufferedReader. So the modified code I am using right now is something like below.

      BufferedReader reader = TimestamperAPI.get().read(currentBuild,"time=HH:mm:ss&appendLog")

          [JENKINS-51106] Empty BufferedReader is returned if we use Java API of Timestamper plug-in without using appendLog param

          Steven G Brown added a comment - - edited

          I'd like to help, but I'm not able to reproduce this. What is the class of the build? Can you put an example project on github which demonstrates the problem?

          Steven G Brown added a comment - - edited I'd like to help, but I'm not able to reproduce this. What is the class of the build? Can you put an example project on github which demonstrates the problem?

          Dinesh Reddy added a comment -

          Hi Steve,

          My job is jenkins pipeline job. Job (written in Groovy) will be building a mobile app and when the build is failed, I will need to send the build log as an attachment in the mail. I tried with the below piece of groovy code to retrieve the the build log.

          protected static String getBuildLogText(jobFullName, buildNumber, script) {
                String buildLogText = ""
                BufferedReader reader
                Jenkins.instance.getItemByFullName(jobFullName).each{ item->
                Run currentBuild = ((Job)item).getBuild(buildNumber)
                if(currentBuild){
                      try {
                            reader = TimestamperAPI.get().read(currentBuild,"time=HH:mm:ss")
                            String line
                            while((line=reader.readLine())!= null){
                                  buildLogText = buildLogText + line + "\n";
                            }
                       } catch (Exception e) {
                            String exceptionMessage = (e.getLocalizedMessage()) ?: 'Failed to capture the Build Log....'
                            script.echoCustom(exceptionMessage,'ERROR',false)
                      } finally {
                            if(reader != null){
                                  reader.close();
                            }
                      }
                }
          }
          buildLogText
          }

          Dinesh Reddy added a comment - Hi Steve, My job is jenkins pipeline job. Job (written in Groovy) will be building a mobile app and when the build is failed, I will need to send the build log as an attachment in the mail. I tried with the below piece of groovy code to retrieve the the build log. protected static String getBuildLogText(jobFullName, buildNumber, script) {       String buildLogText = ""       BufferedReader reader       Jenkins.instance.getItemByFullName(jobFullName).each{ item->       Run currentBuild = ((Job)item).getBuild(buildNumber)       if(currentBuild){             try {                   reader = TimestamperAPI.get().read(currentBuild,"time=HH:mm:ss")                   String line                   while((line=reader.readLine())!= null){                         buildLogText = buildLogText + line + "\n";                   }              } catch (Exception e) {                   String exceptionMessage = (e.getLocalizedMessage()) ?: 'Failed to capture the Build Log....'                   script.echoCustom(exceptionMessage,'ERROR',false)             } finally {                   if(reader != null){                         reader.close();                   }             }       } } buildLogText }

          Steven G Brown added a comment - - edited

          Thanks, that was helpful. I've committed a fix and it will be included in the next release.

          By the way, if you want the entire build log you may find it easier to use the URL:

          def getBuildLogText() {
              new URL(BUILD_URL + "/timestamps/?time=HH:mm:ss&appendLog").getText()
          }
          

          Cheers
          Steve

          Steven G Brown added a comment - - edited Thanks, that was helpful. I've committed a fix and it will be included in the next release. By the way, if you want the entire build log you may find it easier to use the URL: def getBuildLogText() { new URL(BUILD_URL + "/timestamps/?time=HH:mm:ss&appendLog" ).getText() } Cheers Steve

          Dinesh Reddy added a comment -

          Hi Steve,

          Thanks for fixing the issue. I have heard about using the url directly, but we have our own authentication mechanism (OAuth 1.0 service) for jenkins, which is not an easy to implement as of today.

          Thanks

          Dinesh

          Dinesh Reddy added a comment - Hi Steve, Thanks for fixing the issue. I have heard about using the url directly, but we have our own authentication mechanism (OAuth 1.0 service) for jenkins, which is not an easy to implement as of today. Thanks Dinesh

          Fix included in Timestamper 1.8.10 which will be available shortly.

          Steven G Brown added a comment - Fix included in Timestamper 1.8.10 which will be available shortly.

            stevengbrown Steven G Brown
            dinesh_gioe Dinesh Reddy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: