jenkinsci/bitbucket-branch-source-plugin

BitbucketTagSCMHead does not receive an annotated tag date

ryancurrah opened this issue · 6 comments

Jenkins and plugins versions report

Environment
Jenkins: 2.346.1.4
OS: Ubuntu - 18.04
---
cloudbees-bitbucket-branch-source:773.v4b_9b_005b_562b_

What Operating System are you using (both controller, and any agents involved in the problem)?

Controller: ubuntu 1804
Agent: ubuntu 1804

Reproduction steps

  • Install the https://plugins.jenkins.io/bitbucket-scm-filter-aged-refs plugin in Jenkins.
  • Create a Bitbucket project and setup an existing repository with a commit older than one 1 day (I used this repository to test).
  • Setup an Organization Folder to scan the created Bitbucket project, configure Filter by ref age discovery trait, to filter tags created after 1 days. (Remember to enable Discover Tags)
  • Create an annotated git tag (EG git tag -m "" v0.0.0) from a commit that is older than 1 day and push the tag. Click the Scan Multibranch Pipeline Now button in the repository folder. View the logs in Scan Multibranch Pipeline Log.

Expected Results

When the Scan Multibranch Pipeline job runs it should not skip annotated tags that were created less than a day ago where the commit is older than a day.

Actual Results

The bitbucket-branch-source-plugin plugin is not providing the annotated tags create date and instead the commits date to the BitbucketTagSCMHead constructor.

Anything else?

As per GitTagSCMHead class which BitbucketTagSCMHead extends.

The timestamp parameter to the GitTagSCMHead constructor should be...

The timestamp of the tag, for lightweight tags this should be the last commit, for annotated tags this should be the tag date.

Source: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L46-L47

I've spent a day trying to understand this plugins code and I found where the BitbucketTagSCMHead is being constructed but I can't tell how the timestamp value is generated.

Source: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java#L805.

There is a TODO in the code that mentions supporting this, but I have no Idea if it's related or how we would add that support.

Return timestamp of last commit or of tag if its annotated tag.
// TODO figure out how to implement this

Source: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java#L75-L84

If someone could help me understand this a little better I may be able to produce the fix myself.

Is this with Bitbucket Cloud or Bitbucket Server?

On Bitbucket Server, GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags and GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name} return RestTag objects that contain the tag name, tag object ID, and commit ID, but not the tagger date. I don't know whether it is possible to query the tagger date over the REST API, or whether that would require fetching the tag object over the Git protocol (which might then require fetching commit, tree, and blob objects as well).

Sorry that was a newb mistake. I am using Bitbucket server. Interesting that the commit date is determined by querying the API. I'll do some research on the API of Bitbucket server. Though I'm pretty familiar with it and I don't think there is a way to get the tag create date without cloning the project.

I looked at Bitbuckets JIRA issues and found an issue where someone is asking for Bitbucket to support listing tags and getting their create date. I added a comment to it and linked it to this issue.

https://jira.atlassian.com/browse/BSERV-7764