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

Polling latest Change sets P4_CHANGELIST to "now" instead of the CL number

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • p4-plugin
    • P4 Plugin 1.13.3

      If the the `Polling latest Change` filter is applied, the `P4_CHANGELIST` variable is set to the string "now" instead of the CL number.

      This makes it impossible to build a version string containing the CL number whenever that filter is applied.

          [JENKINS-70437] Polling latest Change sets P4_CHANGELIST to "now" instead of the CL number

          Karl Wirth added a comment -

          Hi antemotion,

          How are you starting the job? I have P4-Plugin 1.13.3 installed and if I trigger the job through polling or the 'Poll Now' button I see the correct changelist:

           

          [Polling Latest Change] $ /bin/sh -xe /tmp/jenkins8550472099946037616.sh
          + echo P4_CHANGELIST is:
          P4_CHANGELIST is:
          + echo 2788
          2788 

          If I click the 'Build Now' button I see 'now' because polling did not run:

          [Polling Latest Change] $ /bin/sh -xe /tmp/jenkins5189023387103622461.sh
          + echo P4_CHANGELIST is:
          P4_CHANGELIST is:
          + echo now
          now 

           

           

           

           

          Karl Wirth added a comment - Hi antemotion , How are you starting the job? I have P4-Plugin 1.13.3 installed and if I trigger the job through polling or the 'Poll Now' button I see the correct changelist:   [Polling Latest Change] $ /bin/sh -xe /tmp/jenkins8550472099946037616.sh + echo P4_CHANGELIST is: P4_CHANGELIST is: + echo 2788 2788 If I click the 'Build Now' button I see 'now' because polling did not run: [Polling Latest Change] $ /bin/sh -xe /tmp/jenkins5189023387103622461.sh + echo P4_CHANGELIST is: P4_CHANGELIST is: + echo now now        

          p4karl the job is set to "Build periodically" (it's a nightly build).

          Mattia Affabris added a comment - p4karl the job is set to "Build periodically" (it's a nightly build).

          Karl Wirth added a comment -

          Thanks antemotion. I was easily able to reproduce that behavior.

          Is there a reason you need it to build every night even if there were no changes?

          The "Build periodically" is using 'now' in the sync command which is where P4_CHANGELIST is picked up from:

          P4 Task: syncing files at client/label: now
          ... p4 sync -q /var/lib/jenkins/workspace/Polling Latest Change/...@now

          When using polling an explicit changelist is chosen:

          P4 Task: syncing files at change: 2788
          ... p4 sync -q /var/lib/jenkins/workspace/Polling Latest Change/...@2788 

          The workaround would be to use the 'Poll SCM' build trigger but will only build if the code has changed since the last time it polled.

           

          Reproduction Steps:

          (1) Create a freestyle job 

          (2) Set 'Source Code Management' to 'Perforce Software'.

          (3) Use a manual workspace that syncs whole test depot. For example: 

          //depot/... //${P4_CLIENT}/... 

          (4) Set 'Polling build filters' to 'Polling Latest Change'.

          (5) Set the 'Build Triggers' to 'Build periodically' with a schedule of every minute:

          */1 * * * * 

          (6) Add a build step that displays 'P4_CHANGELIST'. For example on a Linux master or slave use 'Execute Shell' :

          echo P4_CHANGELIST is:
          echo $P4_CHANGELIST
          

          (7) Save the job.

          (8) Wait 1 minute.

          (9) Check the console log for the job just exeuted. You will see 'P4_CHANGELIST' is set to 'now'.

           

          Workaround:

          Use the build trigger 'Poll SCM' instead of 'Build periodically'.

           

          Karl Wirth added a comment - Thanks antemotion . I was easily able to reproduce that behavior. Is there a reason you need it to build every night even if there were no changes? The "Build periodically" is using 'now' in the sync command which is where P4_CHANGELIST is picked up from: P4 Task: syncing files at client/label: now ... p4 sync -q / var /lib/jenkins/workspace/Polling Latest Change/...@now When using polling an explicit changelist is chosen: P4 Task: syncing files at change: 2788 ... p4 sync -q / var /lib/jenkins/workspace/Polling Latest Change/...@2788 The workaround would be to use the 'Poll SCM' build trigger but will only build if the code has changed since the last time it polled.   Reproduction Steps: (1) Create a freestyle job  (2) Set 'Source Code Management' to 'Perforce Software'. (3) Use a manual workspace that syncs whole test depot. For example:  //depot/... //${P4_CLIENT}/... (4) Set 'Polling build filters' to 'Polling Latest Change'. (5) Set the 'Build Triggers' to 'Build periodically' with a schedule of every minute: */1 * * * * (6) Add a build step that displays 'P4_CHANGELIST'. For example on a Linux master or slave use 'Execute Shell' : echo P4_CHANGELIST is: echo $P4_CHANGELIST (7) Save the job. (8) Wait 1 minute. (9) Check the console log for the job just exeuted. You will see 'P4_CHANGELIST' is set to 'now'.   Workaround: Use the build trigger 'Poll SCM' instead of 'Build periodically'.  

          p4karl the workaround works, thanks!

          Mattia Affabris added a comment - p4karl the workaround works, thanks!

          Enno added a comment -

          We had the same issue with a periodically building pipeline, but this was exacerbated by the fact that P4_CHANGELIST is also "now" when using the "Build Now" button. I wasted a lot of time on testing different pipeline configurations this way, never able to get the variable to contain anything else, and have no workaround for that.

          According to the documentation, it should be a number, not "now" (emphasis mine):

          P4_CHANGELIST - The last Perforce changelist number included in the populated workspace.

           

          Enno added a comment - We had the same issue with a periodically building pipeline, but this was exacerbated by the fact that P4_CHANGELIST is also "now" when using the "Build Now" button. I wasted a lot of time on testing different pipeline configurations this way, never able to get the variable to contain anything else, and have no workaround for that. According to the documentation, it should be a number, not "now" (emphasis mine): P4_CHANGELIST - The last Perforce changelist number included in the populated workspace.  

          Karl Wirth added a comment -

          Hi scarab - Thanks for the feedback.

          I agree that the sentence is not 100% accurate. Most of the time P4_CHANGELIST is a changelist number apart from when it's overridden with 'now' ( I can't think of another non numeric case).

          Would you like me to get it changed to:

          P4_CHANGELIST - The last Perforce changelist number included in the populated workspace if available. 

          Karl Wirth added a comment - Hi scarab - Thanks for the feedback. I agree that the sentence is not 100% accurate. Most of the time P4_CHANGELIST is a changelist number apart from when it's overridden with 'now' ( I can't think of another non numeric case). Would you like me to get it changed to: P4_CHANGELIST - The last Perforce changelist number included in the populated workspace if available.

          Enno added a comment -

          What I'd prefer was a reliable way to use the last changelist number (not "now") in my pipeline scripts. The "now" string isn't useful, at least not for what we're trying to do.

          Enno added a comment - What I'd prefer was a reliable way to use the last changelist number (not "now") in my pipeline scripts. The "now" string isn't useful, at least not for what we're trying to do.

          Karl Wirth added a comment -

          HI scarab - Thanks. I will  ping the developers directly to highlight this issue. 

          Karl Wirth added a comment - HI scarab - Thanks. I will  ping the developers directly to highlight this issue. 

          Heiko Nardmann added a comment - - edited

          How about using

          p4 changes -m1

          as a workaround?

          Heiko Nardmann added a comment - - edited How about using p4 changes -m1 as a workaround?

            Unassigned Unassigned
            antemotion Mattia Affabris
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: