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

Build strategy for tags is not working, if you specify ignore tags lesser than 7days

      Build strategy for tags is not working, if you specify ignore tags lesser than 7days

      Multibranch pipeline configuration on Automated build tags, Used Build strategy plugin

      Added Tags–> Ignore tags older than as 1 (Events :No automatic build triggered for 1..

      )

      it works only if you specify as 7 days older.(Anything less than 7 is ignoring automated build trigger for tag)

       

      Is this the expected one? shall we have a tags to restrict to build automatically only if that is less than one day too?

          [JENKINS-57772] Build strategy for tags is not working, if you specify ignore tags lesser than 7days

          Mark Waite added a comment - - edited

          I am unable to duplicate the problem that you are describing. Please provide instructions to create the job which is showing the failure.

          Steps I took attempting to show the failure:

          1. Create a multibranch Pipeline job using the GitHub branch source
          2. Disable all default behaviors (no branch discovery, no pull request discovery)
          3. Add the "Discover tags" behavior
          4. Add the build strategy "Tags" with an empty value for Ignore tags newer than
          5. Change the "Tags" build strategy Ignore tags older than from its default 7 to 1
          6. Run the job, confirm that it selected no tags to be built and no branches to be built (because there have been no tags created on that repository in the last 1 day)

          The job definition I used is uploaded as config.xml

          Mark Waite added a comment - - edited I am unable to duplicate the problem that you are describing. Please provide instructions to create the job which is showing the failure. Steps I took attempting to show the failure: Create a multibranch Pipeline job using the GitHub branch source Disable all default behaviors (no branch discovery, no pull request discovery) Add the "Discover tags" behavior Add the build strategy "Tags" with an empty value for Ignore tags newer than Change the "Tags" build strategy Ignore tags older than from its default 7 to 1 Run the job, confirm that it selected no tags to be built and no branches to be built (because there have been no tags created on that repository in the last 1 day) The job definition I used is uploaded as config.xml

          vinoth SS added a comment -

          when you scan it is not detected tags less than 1 day, but can u create a new tag , It is detected but not triggered automated build.

          vinoth SS added a comment - when you scan it is not detected tags less than 1 day, but can u create a new tag , It is detected but not triggered automated build.

          Mark Waite added a comment -

          I'm not sure I understand your statement.

          I added a new tag called 'temp-tag-a' and then clicked the link to scan the repository. The new tag was detected by the scan and a new build was scheduled.

          I removed the new tag called 'temp-tag-a' and then clicked the link to scan the repository. The deletion of the tag was detected and the job for temp-tag-a was deleted.

          Please provide numbered steps to recreate the problem you are seeing. Others cannot help you if they cannot duplicate the problem you're seeing.

          Mark Waite added a comment - I'm not sure I understand your statement. I added a new tag called 'temp-tag-a' and then clicked the link to scan the repository. The new tag was detected by the scan and a new build was scheduled. I removed the new tag called 'temp-tag-a' and then clicked the link to scan the repository. The deletion of the tag was detected and the job for temp-tag-a was deleted. Please provide numbered steps to recreate the problem you are seeing. Others cannot help you if they cannot duplicate the problem you're seeing.

          vinoth SS added a comment - - edited

          markewaite

          Steps i tried :

          1. Add the "Discover tags" behavior in multibranch pipeline
          2. Add the build strategy "Tags" with an empty value for Ignore tags newer than
          3. Change the "Tags" build strategy Ignore tags older than from its default 7  to 1
          4.  i have created tags, when you manually scan the organization folder again it is working, but not automatically scanning the events and running the tag job is not happening.
          5. Automated tag job and build ran successfully if you have   Ignore tags older than as its default 7. Then whenever you create tags in Bitbucket , Jenkins events scans automatically and trigger the build as well.

           

          hope this is clear...Let me know if im doing anything wrong. Thanks in advance.

          vinoth SS added a comment - - edited markewaite Steps i tried : Add the "Discover tags" behavior in multibranch pipeline Add the build strategy "Tags" with an empty value for  Ignore tags newer than Change the "Tags" build strategy  Ignore tags older than  from its default 7  to 1  i have created tags, when you manually scan the organization folder again it is working, but not automatically scanning the events and running the tag job is not happening. Automated tag job and build ran successfully if you have    Ignore tags older than as  its default 7. Then whenever you create tags in Bitbucket , Jenkins events scans automatically and trigger the build as well.   hope this is clear...Let me know if im doing anything wrong. Thanks in advance.

          Mark Waite added a comment -

          ss_vinoth22 can you also provide the config.xml file from the job that you defined? That will allow comparison with the configuration I'm using successfully.

          When you say:

          not automatically scanning the events and running the tag job is not happening

          I think you mean that the Bitbucket webhook which was registered by the multibranch pipeline is not causing the job to run when a tag is created and pushed to the repository. Is that correct? Were there any other changes pushed to the Bitbucket repository in that time? If the Ignore tags older than is set to 2 instead of 1. does it still behave badly?

          Mark Waite added a comment - ss_vinoth22 can you also provide the config.xml file from the job that you defined? That will allow comparison with the configuration I'm using successfully. When you say: not automatically scanning the events and running the tag job is not happening I think you mean that the Bitbucket webhook which was registered by the multibranch pipeline is not causing the job to run when a tag is created and pushed to the repository. Is that correct? Were there any other changes pushed to the Bitbucket repository in that time? If the Ignore tags older than is set to 2 instead of 1 . does it still behave badly?

          vinoth SS added a comment - - edited

          markewaite

          When you say:

          not automatically scanning the events and running the tag job is not happening

          I think you mean that the Bitbucket webhook which was registered by the multibranch pipeline is not causing the job to run when a tag is created and pushed to the repository. Is that correct? Were there any other changes pushed to the Bitbucket repository in that time? If the Ignore tags older than is set to 2 instead of 1. does it still behave badly?

           

          Yes exactly!! when you create multibranch pipeline is not causing the job to create and run... and there was no other changes has pushed at that time.

          If the Ignore tags older than is set to 2 instead of 1

          yes it works only when i enter 7, i tried all number from 1-6... It didnt causing the job to run.

          Please find the config file attached

          config.xml

          vinoth SS added a comment - - edited markewaite When you say: not automatically scanning the events and running the tag job is not happening I think you mean that the Bitbucket webhook which was registered by the multibranch pipeline is not causing the job to run when a tag is created and pushed to the repository. Is that correct? Were there any other changes pushed to the Bitbucket repository in that time? If the  Ignore tags older than  is set to  2  instead of  1 . does it still behave badly?   Yes exactly!! when you create multibranch pipeline is not causing the job to create and run... and there was no other changes has pushed at that time. If the  Ignore tags older than  is set to  2  instead of  1 yes it works only when i enter 7, i tried all number from 1-6... It didnt causing the job to run. Please find the config file attached config.xml

          vinoth SS added a comment -

          markewaite

          i think i guessed it, may be not sure if that is the way this plugin behaves,

           Ignore tags older than   :    how does this work?

          • Created tag less than 7 days?
          • Created tags against Commits less than 7 days?

          Because i tried to create tag which has older commit didnt triggered the build? But if i create a new commit and create tag against that which is triggering the tag job and build...

          So i guess this works against commit id created less than 7 days.? Correct me if my understanding is wrong?

          vinoth SS added a comment - markewaite i think i guessed it, may be not sure if that is the way this plugin behaves,  Ignore tags older than   :     how does this work? Created tag less than 7 days? Created tags against Commits less than 7 days? Because i tried to create tag which has older commit didnt triggered the build? But if i create a new commit and create tag against that which is triggering the tag job and build... So i guess this works against commit id created less than 7 days.? Correct me if my understanding is wrong?

          Mark Waite added a comment -

          Unfortunately, I'm not sure of the precise intent with that strategy, but what you're describing makes sense to me.

          Mark Waite added a comment - Unfortunately, I'm not sure of the precise intent with that strategy, but what you're describing makes sense to me.

          vinoth SS added a comment -

          I guess plugin should work by Date of tags created and not the commit-id created. Let me if this needs to be changed?

          Because in my scenario developers will create tags once all testing is completed and ready for release to production, by that time this does not build because commit id was created long back, but the tag created against commit id is less than 7 days.

          vinoth SS added a comment - I guess plugin should work by Date of tags created and not the commit-id created. Let me if this needs to be changed? Because in my scenario developers will create tags once all testing is completed and ready for release to production, by that time this does not build because commit id was created long back, but the tag created against commit id is less than 7 days.

          Mark Waite added a comment -

          I haven't done the detailed research to confirm it, but my recollection is that there are two types of tags in git, lightweight tags and tag objects. The strategy may be attempting to handle both cases and thus may be assuming in both cases that the date stamp should be taken from the commit that is the target of the tag. I believe that lightweight tags do not include a separate date. If that was the intent, then using the date of the commit associated with the tag may be how it is intended to work.

          Mark Waite added a comment - I haven't done the detailed research to confirm it, but my recollection is that there are two types of tags in git, lightweight tags and tag objects. The strategy may be attempting to handle both cases and thus may be assuming in both cases that the date stamp should be taken from the commit that is the target of the tag. I believe that lightweight tags do not include a separate date. If that was the intent, then using the date of the commit associated with the tag may be how it is intended to work.

          vinoth SS added a comment -

          ok do we have any way to get the actual tags created date stamp? I think to use this plugin that date will be an appropriate one?

          vinoth SS added a comment - ok do we have any way to get the actual tags created date stamp? I think to use this plugin that date will be an appropriate one?

          vinoth SS added a comment - - edited

          i think 

          1. command gives the tag created date 
             
            git for-each-ref --format="%(refname:short) | %(creatordate)" refs/tags/*
          2. Command returns the commit id date for tags

          git log --date-order --graph --tags --simplify-by-decoration --pretty=format:'%ai %h %d'
          Not sure which one plugin uses to analyse the date?

           

          vinoth SS added a comment - - edited i think  command gives the tag created date    git for-each-ref --format="%(refname:short) | %(creatordate)" refs/tags/* Command returns the commit id date for tags git log --date-order --graph --tags --simplify-by-decoration --pretty=format:'%ai %h %d' Not sure which one plugin uses to analyse the date?  

          Liam Newman added a comment -

          Here is where the plugin tests dates and it uses the "timestamp" of the tag:
          https://github.com/jenkinsci/basic-branch-build-strategies-plugin/blob/master/src/main/java/jenkins/branch/buildstrategies/basic/TagBuildStrategyImpl.java#L152

          It is up to the the implementers of TagSCMHead to provide that:
          https://github.com/jenkinsci/scm-api-plugin/blob/master/src/main/java/jenkins/scm/api/mixin/TagSCMHead.java

          The git plugin does what markewaite described - use the date of tag creation for annotated tags and the date of the last commit for lightweight tags:
          https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L37-L38

          This comment on SO repeats what markewaite said:

          There is no date information attached to a lightweight tag. ... The dates in the output of git log --tags --simplify-by-decoration --pretty="format:%ai %d" are the dates of the objects to which the tags point, not the dates when the tags themselves were created.

          I think either of the command above would have this same problem, but you'd need to test them to be sure. Further, it is likely that this behavior will differ depending on the underlying branch source - git, github, bitbucket, etc.

          Liam Newman added a comment - Here is where the plugin tests dates and it uses the "timestamp" of the tag: https://github.com/jenkinsci/basic-branch-build-strategies-plugin/blob/master/src/main/java/jenkins/branch/buildstrategies/basic/TagBuildStrategyImpl.java#L152 It is up to the the implementers of TagSCMHead to provide that: https://github.com/jenkinsci/scm-api-plugin/blob/master/src/main/java/jenkins/scm/api/mixin/TagSCMHead.java The git plugin does what markewaite described - use the date of tag creation for annotated tags and the date of the last commit for lightweight tags: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L37-L38 This comment on SO repeats what markewaite said: There is no date information attached to a lightweight tag. ... The dates in the output of git log --tags --simplify-by-decoration --pretty="format:%ai %d" are the dates of the objects to which the tags point, not the dates when the tags themselves were created. I think either of the command above would have this same problem, but you'd need to test them to be sure. Further, it is likely that this behavior will differ depending on the underlying branch source - git, github, bitbucket, etc.

          vinoth SS added a comment -

          it makes sense, I think we need to create annotated tags would actually trigger the job build automatically.

          if people created the lightweight tags, you should note that the tag created date would be last commit date

          Note:  date of tag creation for annotated tags and the date of the last commit for lightweight tags:
          https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L37-L38

          vinoth SS added a comment - it makes sense, I think we need to create annotated tags would actually trigger the job build automatically. if people created the lightweight tags, you should note that the tag created date would be last commit date Note:  date of tag creation for annotated tags and the date of the last commit for lightweight tags: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L37-L38

          The plugin uses annotated tag's commit timestamp instead of tag created timestamp and use it to compare with the value in the setting "Ignore tags older than".

          Environment:
          Jenkins v2.235.5
          Basic Branch Build Strategies Plugin v1.3.2
          Bitbucket v6.10.0

          To Duplicate this issue,
          1. Set "Ignore tags older than" to 3 and "Ignore tags newer than" to empty string in the project configuration
          2. Create an annotated tag on a commit older than 3 days.
          3. Observe that the tags tab creates a job for the created annotated tag but it doesn't build. It is expected to build, as the tag creation time is less than 3 days and as per the inline help message - "The number of days since the tag was created after which it is no longer eligible for automatic building".
          4. The behavior is same on the annotated tags

          I hope the expected behavior is to consider the tag creation time (not the associated commit time of the tag) for build strategy comparison.

          Shankar Ramasamy added a comment - The plugin uses annotated tag's commit timestamp instead of tag created timestamp and use it to compare with the value in the setting "Ignore tags older than". Environment: Jenkins v2.235.5 Basic Branch Build Strategies Plugin v1.3.2 Bitbucket v6.10.0 To Duplicate this issue, 1. Set "Ignore tags older than" to 3 and "Ignore tags newer than" to empty string in the project configuration 2. Create an annotated tag on a commit older than 3 days. 3. Observe that the tags tab creates a job for the created annotated tag but it doesn't build. It is expected to build, as the tag creation time is less than 3 days and as per the inline help message - "The number of days since the tag was created after which it is no longer eligible for automatic building". 4. The behavior is same on the annotated tags I hope the expected behavior is to consider the tag creation time (not the associated commit time of the tag) for build strategy comparison.

          Rozg Onik added a comment -

          Our systems are also affected by this bug therefore I have managed to do the following investigation:

          As people here pointed out the git plugin should use the tag's creation date in case of an annotated tag as written here: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L37-L38

          Problem is I can not find any references to GitTagSCMHead where instantiation happens with the tag's timestamp.
          Instead I only find references where it uses the underlying commit's timestamp:

          So I think the root cause for this issue is the git plugin does not consider using an annotated tag's timestamp to GitTagSCMHead.
          I will open a new issue about that in the git plugin component.

          Environment:
          Jenkins v2.319.3
          Basic Branch Build Strategies Plugin v1.3.2
          Git Plugin v4.10.3

          Rozg Onik added a comment - Our systems are also affected by this bug therefore I have managed to do the following investigation: As people here pointed out the git plugin should use the tag's creation date in case of an annotated tag as written here: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L37-L38 Problem is I can not find any references to GitTagSCMHead where instantiation happens with the tag's timestamp. Instead I only find references where it uses the underlying commit's timestamp: https://github.com/jenkinsci/git-plugin/blob/5e7d735c4d24a6e54a7494381a0f6e80dd5f948c/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java#L765 https://github.com/jenkinsci/git-plugin/blob/5e7d735c4d24a6e54a7494381a0f6e80dd5f948c/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java#L990 So I think the root cause for this issue is the git plugin does not consider using an annotated tag's timestamp to GitTagSCMHead. I will open a new issue about that in the git plugin component. Environment: Jenkins v2.319.3 Basic Branch Build Strategies Plugin v1.3.2 Git Plugin v4.10.3

            Unassigned Unassigned
            ss_vinoth22 vinoth SS
            Votes:
            3 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated: