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

JiraProjectProperty.setSites() doesn't set sites, it adds them (resulting in duplicate sites)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • jira-plugin
    • None

      Jenkins: v2.44
      JIRA plugin: v2.3

      In v2.3 (currently the latest) of the JIRA plugin, I believe there is a bug in JiraProjectProperty.

      The issue is in the setSites() method here:

      https://github.com/jenkinsci/jira-plugin/blob/7600eb9c12559119d9599cdeaa088862a5c6dfc3/src/main/java/hudson/plugins/jira/JiraProjectProperty.java#L94-L96

      It is currently written as follows:

      public void setSites(JiraSite site) {
          sites.add(site);
      }
      

      The issue specifically is that the setSites() is behaving more like an "add site" command. This can result in duplicate JiraSite objects ending up in your config.

      Steps to Reproduce:

      I first noticed this tonight when attempting to configure the JIRA plugin with a Groovy script. In the Groovy script (see below), I create a JiraSite object, then save it to the instance with "setSites()".

      Every time I run the Groovy script, however, an additional entry for my single JIRA site is added to my instance.

      import hudson.plugins.jira.*
      import jenkins.model.*
      import java.net.URL
      
      // create JiraSite object
      URL url = new URL("http://foo.atlassian.net/")
      URL alternativeUrl = null
      String userName = "hello@foo.com"
      String password = "my-password-here"
      boolean supportsWikiStyleComment = true
      boolean recordScmChanges = true
      String userIssuePattern = ""
      boolean updateJiraIssueForAllBuildStatus = true
      String groupVisibility = ""
      String roleVisibility = ""
      boolean useHTTPAuth = false
      def site = new JiraSite(url, alternativeUrl, userName, password, supportsWikiStyleComment, recordScmChanges, userIssuePattern, updateJiraIssueForAllBuildStatus, groupVisibility, roleVisibility, useHTTPAuth)
      
      // call setSites() to save the JiraSite
      def instance = Jenkins.getInstance()
      jiraPlugin = instance.getDescriptorByType(hudson.plugins.jira.JiraProjectProperty.DescriptorImpl)
      jiraPlugin.setSites(site)
      jiraPlugin.save()
      

      Expected Behavior:

      • Calling setSites() should behave like a true "set" operation.
      • You should be able to call setSites() as many times as you want, but if you're only ever passing in one JiraSite, then you should end up with one JiraSite in your instance.

      Actual Behavior:

      • Calling setSites() is currently behaving like an "add" operation.
      • If you run this script 10 times, but you're only ever passing in one JiraSite, you'll end up with 10 duplicate JIRA projects configured.

            Unassigned Unassigned
            sbaker Steven Baker
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: