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

p4.client.ConnectionHelper is not able to find proper credentials, hence P4Trigger.matchServer always fails

XMLWordPrintable

      Hello

      Already did quite debugging through our Jenkins instance script console.

      We are using Jenkins 2.235.1, P4 plugin 1.10.13. I have a Pipeline job with Jenkinsfile from SCM, manual run works, P4 triggers never actually run any job (logs are getting stopped at "Probe", never got to "Poke").

      Here are how our credentials currently look like (under folder, jenkins_url/job/my_folderA/credentials/):

      Sorry for that amount, but initially I was thinking it's about port string matching, tried everything (proxy, etc).

      This is the script with commands I used based on github repo with links attached.

      import org.jenkinsci.plugins.p4.trigger.P4Trigger
      import org.jenkinsci.plugins.p4.trigger.P4Hook
      import jenkins.triggers.SCMTriggerItem;
      import org.jenkinsci.plugins.p4.PerforceScm;
      import org.jenkinsci.plugins.p4.client.ConnectionHelper;
      import org.jenkinsci.plugins.p4.credentials.P4BaseCredentials;
      import hudson.security.ACL;
      import com.cloudbees.plugins.credentials.domains.DomainRequirement;
      import org.acegisecurity.Authentication;
      import com.cloudbees.plugins.credentials.CredentialsProvider;
      
      Jenkins.instance.getAllItems(AbstractItem.class).each {
      
        if(it.fullName.contains("test_p4_internal_tools_integration-dns")) {
          println(it.fullName)
          job = it
        }
      }
      
      println("mimicing p4 stuff about matching server")
      // https://github.com/jenkinsci/p4-plugin/blob/e48626f04ebc1ce7f7b3dcba8bcc3195800187cb/src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java#L117
      SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job)
      println("item=" + item)
      
      scmTrigger = item.getSCMs()[0]
      println(scmTrigger)
      
      PerforceScm p4scm = PerforceScm.convertToPerforceScm(scmTrigger);
      println(p4scm)
      
      println()
      
      println("getting credentials from p4 scm")
      String id = p4scm.getCredential();
      println(id)
      println("these already are correct")
      println()
      
      println("getting credentials from connection helper")
      P4BaseCredentials credential = ConnectionHelper.findCredential(id);
      println(credential)
      println("these is null? investigating further")
      println()
      
      println("Mimicing Connection helper, which seems to be used in a deprecated way? ")
      // https://github.com/jenkinsci/p4-plugin/blob/e48626f04ebc1ce7f7b3dcba8bcc3195800187cb/src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java#L125
      //	@Deprecated
      //	public static P4BaseCredentials findCredential(String id)
      //  Use {@link #findCredential(String, ItemGroup)} or {@link #findCredential(String, Item)}
      Class<P4BaseCredentials> type = P4BaseCredentials.class;
      Jenkins scope = Jenkins.getInstance();
      Authentication acl = ACL.SYSTEM;
      DomainRequirement domain = new DomainRequirement();
      
      List<P4BaseCredentials> list;
      list = CredentialsProvider.lookupCredentials(type, scope, acl, domain);
      
      println()
      println("Iterating over found ids in deprecated way")
      for (P4BaseCredentials c : list) {
        println(c)
        println(c.getId())
      }
      println("Done. Found only First Jenkins credential ??")
      
      
      println()
      println("Trying out proposed method from deprecation with a job as a item argument")
      P4BaseCredentials credential2 = ConnectionHelper.findCredential(id, job);
      println(credential2.id)
      println("success")

       

      And this is the output:

      mmatczak/my_job_name
      mimicing p4 stuff about matching server
      item=org.jenkinsci.plugins.workflow.job.WorkflowJob@f268a73[mmatczak/my_job_name]
      org.jenkinsci.plugins.p4.PerforceScm@74f88dbf
      org.jenkinsci.plugins.p4.PerforceScm@74f88dbf
      
      getting credentials from p4 scm
      11e31****************************
      these already are correct
      
      getting credentials from connection helper
      null
      these is null? investigating further
      
      Mimicing Connection helper, which seems to be used in a deprecated way? 
      
      Iterating over found ids in deprecated way
      org.jenkinsci.plugins.p4.credentials.P4PasswordImpl@e822e5d7
      8f66*****************************
      Done. Found only First Jenkins credential ??
      
      Trying out proposed method from deprecation with a job as a item argument
      11e31****************************
      success

       

      Short summary what I think is happening:

      https://github.com/jenkinsci/p4-plugin/blob/e48626f04ebc1ce7f7b3dcba8bcc3195800187cb/src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java#L125

      uses deprecated method from ConnectionHelper as stated here (which returns null, so matchServer returns false): https://github.com/jenkinsci/p4-plugin/blob/e48626f04ebc1ce7f7b3dcba8bcc3195800187cb/src/main/java/org/jenkinsci/plugins/p4/client/ConnectionHelper.java#L839

      When I added my job as a second argument it was able to fetch correct credentials.

      If I missed any info needed - please let me know.

      Thanks!

      Maciej

            p4karl Karl Wirth
            mmatczak Maciej Matczak
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: