Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PLUGIN_BRANCH for Automatically Populating Branch Information in Build Post Call #23

Open
Ompragash opened this issue Sep 12, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Ompragash
Copy link
Member

Description:

This enhancement proposes adding a new plugin configuration option PLUGIN_BRANCH. When this option is enabled, the plugin will automatically populate the branch name and repository URI (similar to how Jenkins’ Jira plugin works) in the build post call to Jira. If PLUGIN_BRANCH is not passed, the plugin will continue with its current behavior without including branch information.

Problem:

Currently, the Drone Jira plugin does not include any branch-specific information (e.g., branch name and repository URI) in the build post call to Jira. This limits the plugin’s usefulness in environments where multiple branches are in use, such as feature or bugfix branches, as branch-specific details aren’t tracked. Without these details, users can’t easily trace which branch a particular build came from in Jira.

Solution:

Add a new PLUGIN_BRANCH setting to the Drone Jira plugin. When enabled, the plugin will automatically extract the branch name and repository URI from the build context and pass this information in the build payload to Jira. This behavior will mirror the way Jenkins’ Jira plugin works.

If PLUGIN_BRANCH is not set, the plugin will behave as it currently does, excluding the branch information from the payload. This ensures that existing users aren’t impacted by this change.

Example Usage:

  1. If PLUGIN_BRANCH is passed, the build payload sent to Jira will look something like this:
{
  "builds": [
    {
      "buildNumber": 123,
      "description": "Sample build description",
      "displayName": "Sample Build",
      "url": "https://your-ci-system/build/123",
      "lastUpdated": "2024-09-12T10:00:00Z",
      "pipelineId": "your-pipeline-id",
      "issueKeys": ["ISSUE-123"],
      "state": "successful",
      "updateSequenceNumber": 123,
      "references": [
        {
          "commit": {
            "id": "08cd9c26b2b8d7cf6e6af6b49da8895d065c259f",
            "repositoryUri": "https://bitbucket.org/atlassian/biij-vendor-api"
          },
          "ref": {
            "name": "feature/ISSUE-123-some-work",
            "uri": "https://bitbucket.org/atlassian/biij-vendor-api/refs/feature/ISSUE-123-some-work"
          }
        }
      ]
    }
  ]
}
  1. If PLUGIN_BRANCH is not passed, the references field will simply be omitted.
@Ompragash Ompragash added the enhancement New feature or request label Sep 12, 2024
@bradrydzewski
Copy link
Member

@Ompragash branch and repository are automatically passed to every plugin vs the DRONE_BRANCH environment variable, so we should not need to ask the user to specify branch. You can see a list of environment variables automatically passed to all plugins here: https://docs.drone.io/pipeline/environment/reference/

here you can see how we use these for the Slack plugin:
https://github.com/drone-plugins/drone-slack/blob/master/main.go#L106

@Ompragash
Copy link
Member Author

@bradrydzewski, I reviewed the plugin code and noticed it already utilizes SCM variables. Currently, branch information is not passed in the Build call. To avoid altering the existing functionality and mainly to align with the behavior of the Jenkins Jira Plugin, I proposed adding a new PLUGIN_BRANCH setting.

so we should not need to ask the user to specify branch.

in that case, we can include the branch details in the Build call by default.

something like this matching the JIRA API build call format
func toBranchReference(args Args) []Reference {
    return []Reference{
        {
            Commit: Commit{
                ID: args.Commit.Rev,
                RepositoryURI: args.Commit.Link,
            },
            Ref: Ref{
                Name: args.Commit.Branch,  // Branch name
                URI:  fmt.Sprintf("%s/refs/%s", args.Commit.Link, args.Commit.Branch), // Branch URI
            },
        },
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants