Skip to content

Commit

Permalink
[JENKINS-28367] fallback on 'p4 login -p' when '-a' fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetti committed May 14, 2015
1 parent a8e1f72 commit 55762a9
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -616,8 +616,16 @@ protected void login() throws PerforceException {
* @throws PerforceException if the execution of the p4Exe fails
*/
private String p4Login(String p4Exe) throws IOException, PerforceException {
try {
return p4Login(new String[] { p4Exe, "login", "-a", "-p" });
} catch (PerforceException e) {
return p4Login(new String[] { p4Exe, "login", "-p" });
}
}

private String p4Login(String[] p4Cmd) throws IOException, PerforceException {
Executor login = depot.getExecFactory().newExecutor();
login.exec(new String[] { p4Exe, "login", "-a", "-p" });
login.exec(p4Cmd);

try {
// "echo" the password for the p4 process to read
Expand Down

6 comments on commit 55762a9

@ybdesire
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Rob for the fix. I think the code change is okay for my issue. How can I update my plugin for the fix?

@rpetti
Copy link
Member Author

@rpetti rpetti commented on 55762a9 May 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not released yet since I haven't had any time to test it.
Here's a snapshot containing the fix if you want to test it: https://dl.dropboxusercontent.com/u/1897231/perforce.hpi

@mjdetullio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change does effectively nothing, since there is no detection for the error that doesn't allow the -a option.

If -a is not allowed, p4 outputs User not allowed to create a ticket that is valid on all host machines. with exit value 1. This isn't detected by checkAuthnErrors(String), so a PerforceException is never thrown and p4 login -p never gets called.

@rpetti
Copy link
Member Author

@rpetti rpetti commented on 55762a9 Jun 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this?

@mjdetullio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we're getting auth errors right now when attempting to use a server that does not allow the -a option.

Only p4 login -a -p gets executed then attempts to run p4 workspace -o again without falling back to p4 login -p.

I haven't had a chance to actually load up the IDE and make a change to test out, but after carefully looking through the source I'm 99% certain this is the problem. I think adding User not allowed to create a ticket that is valid on all host machines. to private static final String p4errors[] would solve the problem.

Using remote perforce client: jenkins-test_job--111504876
[test_job] $ p4 workspace -o jenkins-test_job--111504876
[test_job] $ p4 login -a -p
[test_job] $ p4 workspace -o jenkins-test_job--111504876
Caught exception communicating with perforce. Perforce password (P4PASSWD) invalid or unset.com.tek42.perforce.PerforceException: Perforce password (P4PASSWD) invalid or unset.
    at com.tek42.perforce.parse.AbstractPerforceTemplate.getPerforceResponse(AbstractPerforceTemplate.java:406)
    at com.tek42.perforce.parse.AbstractPerforceTemplate.getPerforceResponse(AbstractPerforceTemplate.java:301)
    at com.tek42.perforce.parse.Workspaces.getWorkspace(Workspaces.java:61)
    at hudson.plugins.perforce.PerforceSCM.getPerforceWorkspace(PerforceSCM.java:1641)
    at hudson.plugins.perforce.PerforceSCM.getPerforceWorkspace(PerforceSCM.java:1602)
    at hudson.plugins.perforce.PerforceSCM.checkout(PerforceSCM.java:907)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1282)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:610)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:532)
    at hudson.model.Run.execute(Run.java:1744)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:374)
ERROR: Unable to communicate with perforce. Perforce password (P4PASSWD) invalid or unset.

@mjdetullio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request inbound

Please sign in to comment.