hudson.model.Failure Java Examples

The following examples show how to use hudson.model.Failure. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OicSession.java    From oic-auth-plugin with MIT License 6 votes vote down vote up
/**
 * When the identity provider is done with its thing, the user comes back here.
 * @return an {@link HttpResponse}
 */
public HttpResponse doFinishLogin(StaplerRequest request)  {
    StringBuffer buf = request.getRequestURL();
    if (request.getQueryString() != null) {
        buf.append('?').append(request.getQueryString());
    }
    AuthorizationCodeResponseUrl responseUrl = new AuthorizationCodeResponseUrl(buf.toString());
    if (!state.equals(responseUrl.getState())) {
        return new Failure("State is invalid");
    }
    String code = responseUrl.getCode();
    if (responseUrl.getError() != null) {
        return new Failure(
                "Error from provider: " + responseUrl.getError() + ". Details: " + responseUrl.getErrorDescription()
        );
    } else if (code == null) {
        return new Failure("Missing authorization code");
    } else {
        return onSuccess(code);
    }
}
 
Example #2
Source File: ValidationTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void validatePluginNoCredentialsFailure() {
    final String error = "AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified." + System.lineSeparator() +
            "The AWS credentials provided are not valid.";

    thrown.expect(Failure.class);
    thrown.expectMessage(error);

    Validation.validatePlugin(
            null,
            null,
            "us-east-1",
            CategoryType.Build.getName(),
            "Jenkins-Build",
            "1",
            "ProjectName",
            null);
}
 
Example #3
Source File: ValidationTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void validatePluginNoRegionFailure() {
    final String error = "AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified." + System.lineSeparator();
    final String regionError =  "The specified AWS region is not valid.";

    thrown.expect(Failure.class);
    thrown.expectMessage(error);
    thrown.expectMessage(regionError);

    Validation.validatePlugin(
            "",
            "",
            "",
            CategoryType.Build.getName(),
            "Jenkins-Build",
            "1",
            "ProjectName",
            null);
}
 
Example #4
Source File: ValidationTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void validatePluginInvalidActionTypeProviderFailure() {
    final String error = "AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified." + System.lineSeparator();

    thrown.expect(Failure.class);
    thrown.expectMessage(error);
    thrown.expectMessage("Category:");
    thrown.expectMessage("Version: 1");
    thrown.expectMessage("Provider:");

    Validation.validatePlugin(
            "",
            "",
            "us-east-1",
            CategoryType.Build.getName(),
            "",
            "1",
            "ProjectName",
            null);
}
 
Example #5
Source File: ValidationTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void validatePluginInvalidActionTypeCategoryFailure() {
    final String error = "AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified." + System.lineSeparator();

    thrown.expect(Failure.class);
    thrown.expectMessage(error);
    thrown.expectMessage("Category: Please Choose A Category");
    thrown.expectMessage("Version: 1");
    thrown.expectMessage("Provider: Jenkins-Build");

    Validation.validatePlugin(
            "",
            "",
            "us-east-1",
            CategoryType.PleaseChooseACategory.getName(),
            "Jenkins-Build",
            "1",
            "ProjectName",
            null);
}
 
Example #6
Source File: ValidationTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void validatePluginInvalidActionTypeVersionFailure() {
    final String error = "AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified." + System.lineSeparator();

    thrown.expect(Failure.class);
    thrown.expectMessage(error);
    thrown.expectMessage("Category: Build");
    thrown.expectMessage("Version:");
    thrown.expectMessage("Provider: Jenkins-Build");

    Validation.validatePlugin(
            "",
            "",
            "us-east-1",
            CategoryType.Build.getName(),
            "Jenkins-Build",
            "",
            "ProjectName",
            null);
}
 
Example #7
Source File: ValidationTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void validatePluginAllFieldsMissingFailure() {
    thrown.expect(Failure.class);
    thrown.expectMessage("AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified.");
    thrown.expectMessage("The specified AWS region is not valid.");
    thrown.expectMessage("The AWS credentials provided are not valid.");

    Validation.validatePlugin(
            null,
            null,
            "",
            CategoryType.Build.getName(),
            "Jenkins-Build",
            "",
            "ProjectName",
            null);
}
 
Example #8
Source File: AbstractMultiBranchCreateRequest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
private void validateInternal(String name, BlueScmConfig scmConfig, BlueOrganization organization) {

        checkUserIsAuthenticatedAndHasItemCreatePermission(organization);

        // If scmConfig is empty then we are missing the uri and name
        if (scmConfig == null) {
            throw fail(new Error("scmConfig", ErrorCodes.MISSING.toString(), "scmConfig is required"));
        }

        if (scmConfig.getUri() == null) {
            throw fail(new Error(ERROR_FIELD_SCM_CONFIG_URI, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_URI + " is required"));
        }

        if (getName() == null) {
            throw fail(new Error(ERROR_FIELD_SCM_CONFIG_NAME, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_NAME + " is required"));
        }

        List<Error> errors = Lists.newLinkedList(validate(name, scmConfig));

        // Validate that name matches rules
        try {
            Jenkins.getInstance().getProjectNamingStrategy().checkName(getName());
            Jenkins.checkGoodName(name);
        }catch (Failure f){
            errors.add(new Error(ERROR_FIELD_SCM_CONFIG_NAME, Error.ErrorCodes.INVALID.toString(),  getName() + " in not a valid name"));
        }

        ModifiableTopLevelItemGroup parent = getParent(organization);

        if (parent.getItem(name) != null) {
            errors.add(new Error(ERROR_NAME, Error.ErrorCodes.ALREADY_EXISTS.toString(), getName() + " already exists"));
        }

        if(!errors.isEmpty()){
            throw fail(errors);
        }
    }