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

email-ext - Incorrect build status when used in pipline before build

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      We are using Email Extension plugin to send emails before build.
      Default subject is defined as

      $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!
      

       
      Our Jenkins and email-ext plugin versions are

      Jenkins: 2.235.2
      Email Extension Plugin: 2.69
      

       

      In Freestyle project, Editable Email Notification for Before build it is defined like this 

      When email arrives from Freestyle project, subject for $BUILD_STATUS has value Building and it looks like this

      In Pipeline project there is not explicit command for before build, so we simply used this code below in stage before actual build

      emailext from: EMAIL_FROM, to: '${DEFAULT_RECIPIENTS}', replyTo: '$DEFAULT_REPLYTO', mimeType: 'text/html; charset=UTF-8', subject: '${DEFAULT_SUBJECT}', body: '${DEFAULT_CONTENT}', postsendScript: '${DEFAULT_POSTSEND_SCRIPT}', presendScript: '${DEFAULT_PRESEND_SCRIPT}', recipientProviders: [developers(), requestor(), upstreamDevelopers()]
      

      When email arrives from Pipeline project, subject for $BUILD_STATUS has value SUCCESS and it looks like this

      which is incorrect because the build stage is not jet started.

      We also defined sending email in post stageon Success for both Freestyle and Pipeline project, and when email arrives it has Successful string in subject. That is working OK.

      It seems that in pipeline case, for before build, $BUILD_STATUS in subject is not correctly replaced with Building string. Instead it is replaced with SUCCESS string what is misleading because build nor the other stages were finished.

        Attachments

          Activity

          Hide
          slide_o_mix Alex Earl added a comment -

          In pipeline you control the build status during the build. You can set the status to whatever you want during the build. If the build has not failed yet, then it is considered successful. You may need to change your DEFAULT_SUBJECT to something different and manage the status internally. Also, the BUILD_STATUS macro is actually part of the token-macro-plugin, not email-ext.

          Show
          slide_o_mix Alex Earl added a comment - In pipeline you control the build status during the build. You can set the status to whatever you want during the build. If the build has not failed yet, then it is considered successful. You may need to change your DEFAULT_SUBJECT to something different and manage the status internally. Also, the BUILD_STATUS macro is actually part of the token-macro-plugin, not email-ext.
          Hide
          cmd_zed Cmd Zed added a comment -

          Yes, I agree that I can control status during the build, but we can also agree that the $BUILD_STATUS in email subject, Building and Successful, is not actually status during the build. So, I would say that the issue is not with actual built status rather with replacing $BUILD_STATUS with correct value that is the case with Freestyle projects.

          Sure, I can manually construct the email subject string, but why it works correctly in post stage/section with Successful without writing any custom logic for setting subject? I expected that email-ext plugin will rid me of doing it manually, especially when email-ext is doing that in Freestyle project by it self. 

          If I understand you correctly the issue is with token-macro-plugin not with email-ext? But the token-macro plugin is dependency of email-ext, so if dependency is working incorrectly then the product that uses that dependency also works incorrectly. What I want to say is, it is strange that token-macro-plugin and email-ext work correctly in Freestyle project but they doesn't work in Pipeline project for Before build. There is obliviously some way in Freestyle project how email-ext plugin instructs token-macro plugin to set Building in $BUILD_STATUS variable. There should be the same way to achieve that in Pipeline project with Pipeline Syntax for email-ext.

          Show
          cmd_zed Cmd Zed added a comment - Yes, I agree that I can control status during the build, but we can also agree that the $BUILD_STATUS in email subject, Building and Successful , is not actually status during the build. So, I would say that the issue is not with actual built status rather with replacing $BUILD_STATUS with correct value that is the case with Freestyle projects. Sure, I can manually construct the email subject string, but why it works correctly in post stage/section with Successful without writing any custom logic for setting subject? I expected that email-ext plugin will rid me of doing it manually, especially when email-ext is doing that in Freestyle project by it self.  If I understand you correctly the issue is with token-macro-plugin not with email-ext? But the token-macro plugin is dependency of email-ext, so if dependency is working incorrectly then the product that uses that dependency also works incorrectly. What I want to say is, it is strange that token-macro-plugin and email-ext work correctly in Freestyle project but they doesn't work in Pipeline project for Before build. There is obliviously some way in Freestyle project how email-ext plugin instructs token-macro plugin to set Building in $BUILD_STATUS variable. There should be the same way to achieve that in Pipeline project with Pipeline Syntax for email-ext.
          Hide
          slide_o_mix Alex Earl added a comment -

          FreeStyle jobs and pipeline jobs run in a very different way. In FreeStyle jobs, the order is very specific as to when things can run, for instance, in FreeStyle jobs, email-ext is a publisher plugin which can only run at the end of a job when the actual job steps are complete, thus it has access to the result of the build, or when run as a pre-build trigger, can know the specific state of the job. In pipeline, the state can change between steps and email-ext is just like any other step, it can run at any point when the result of the build is not known. So, it's not strange at all the in FreeStyle you see what you see and in pipeline you see what you see. They run very differently.

          Show
          slide_o_mix Alex Earl added a comment - FreeStyle jobs and pipeline jobs run in a very different way. In FreeStyle jobs, the order is very specific as to when things can run, for instance, in FreeStyle jobs, email-ext is a publisher plugin which can only run at the end of a job when the actual job steps are complete, thus it has access to the result of the build, or when run as a pre-build trigger, can know the specific state of the job. In pipeline, the state can change between steps and email-ext is just like any other step, it can run at any point when the result of the build is not known. So, it's not strange at all the in FreeStyle you see what you see and in pipeline you see what you see. They run very differently.

            People

            Assignee:
            slide_o_mix Alex Earl
            Reporter:
            cmd_zed Cmd Zed
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: