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

User email sync is using deprecated api causing duplicates

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • p4-plugin
    • None

      The

      	public void setChange(ConnectionHelper p4, IChangelistSummary changelist) throws Exception {
      
      		// set id
      		int changeId = changelist.getId();
      		id = new P4ChangeRef(changeId);
      
      		// set author
      		String user = changelist.getUsername();
      		author = User.get(user);
      
      		// set email property on user
      		String email = p4.getEmail(user);
      

      author = User.get(user) is not working due to the different ways users can be configured in jenkins

      The User.get(string) is also marked as depreciated

      simple example

      FYI : our p4 returns user names not emails
      We use Role management with the Azure AD authentication

      import hudson.model.User  
      import org.jenkinsci.plugins.p4.email.P4UserProperty
      
      u1=User.get('Morne.Joubert@u-blox.com',false)
      println("id=${u1}")
      println("fullname=${u1.getFullName()}")
      println('email='+u1.getProperty(hudson.tasks.Mailer.UserProperty.class).getAddress())
      println('p4email='+u1.getProperty(org.jenkinsci.plugins.p4.email.P4UserProperty.class).getEmail())
      
      println('')
      
      u1=User.get('0d25c253d4150d25c253d4150d25c253d415',false)
      println("id=${u1}")
      println("fullname=${u1.getFullName()}")
      println('email='+u1.getProperty(hudson.tasks.Mailer.UserProperty.class).getAddress())
      println('p4email='+u1.getProperty(org.jenkinsci.plugins.p4.email.P4UserProperty.class).getEmail())
      println('')
      
      u1=User.get('username',false)
      println("id=${u1}")
      println("fullname=${u1.getFullName()}")
      println('email='+u1.getProperty(hudson.tasks.Mailer.UserProperty.class).getAddress())
      println('p4email='+u1.getProperty(org.jenkinsci.plugins.p4.email.P4UserProperty.class).getEmail())
      println('')
      
      

      gives

      // first one i get back the Azure ID based on my email
      id=0d25c253d4150d25c253d4150d25c253d415
      fullname=Morne Joubert
      email=Morne.Joubert@u-blox.com
      p4email=null
      
      // second way i get the same user based on the Azure id
      id=0d25c253d4150d25c253d4150d25c253d415
      fullname=Morne Joubert
      email=Morne.Joubert@u-blox.com
      p4email=null
      
      // p4 plugin creates another user based on my username
      id=mjou
      fullname=mjou
      email=morne.joubert@u-blox.com
      p4email=morne.joubert@u-blox.com
      

      Could the p4 plugin first check to see if there is a jenkins user based on the p4 user's email ?
      And only then fall back to the creation ?

            Unassigned Unassigned
            mornejoubert Morne Joubert
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: