Java Code Examples for hudson.model.Item#getFullName()

The following examples show how to use hudson.model.Item#getFullName() . 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: GithubScmContentProvider.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public Object saveContent(@Nonnull StaplerRequest staplerRequest, @Nonnull Item item) {
    JSONObject body;
    try {
        body = JSONObject.fromObject(IOUtils.toString(staplerRequest.getReader()));
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException("Failed to read request body");
    }
    body.put("$class", "io.jenkins.blueocean.blueocean_github_pipeline.GithubScmSaveFileRequest");

    GithubScmSaveFileRequest request = staplerRequest.bindJSON(GithubScmSaveFileRequest.class, body);
    if(request == null){
        throw new ServiceException.BadRequestException(new ErrorMessage(400, "Failed to bind request"));
    }

    ScmContentProvider scmContentProvider = ScmContentProvider.resolve(item);

    if(scmContentProvider != null){
        return saveContent(request, item);
    }
    throw new ServiceException.BadRequestException("No save scm content provider found for pipeline: " + item.getFullName());
}
 
Example 2
Source File: S3ItemStorage.java    From jobcacher-plugin with MIT License 4 votes vote down vote up
@Override
public S3ObjectPath getObjectPath(Item item, String path) {
    S3Profile profile = new S3Profile(lookupCredentials(), 5, 5L);

    return new S3ObjectPath(profile, bucketName, region, item.getFullName(), path);
}
 
Example 3
Source File: AbstractScmContentProvider.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public Object getContent(@Nonnull StaplerRequest request, @Nonnull Item item) {
    String path = StringUtils.defaultIfEmpty(request.getParameter("path"), null);
    String type = StringUtils.defaultIfEmpty(request.getParameter("type"), null);
    String repo = StringUtils.defaultIfEmpty(request.getParameter("repo"), null);
    String branch = StringUtils.defaultIfEmpty(request.getParameter("branch"),null);

    List<ErrorMessage.Error> errors = new ArrayList<>();

    if(!(item instanceof MultiBranchProject) && repo == null){
        errors.add(
                new ErrorMessage.Error("repo",ErrorMessage.Error.ErrorCodes.MISSING.toString(),
                        String.format("repo and branch parameters are required because pipeline %s is not a multi-branch project ",
                                item.getFullName())));
    }

    if(type != null && !type.equals("file")){
        errors.add(
                new ErrorMessage.Error("file",ErrorMessage.Error.ErrorCodes.INVALID.toString(),
                        String.format("type %s not supported. Only 'file' type supported.", type)));
    }


    if(path == null){
        errors.add(
                new ErrorMessage.Error("path",ErrorMessage.Error.ErrorCodes.MISSING.toString(),
                        "path is required query parameter"));
    }
    if(!errors.isEmpty()){
        throw new ServiceException.BadRequestException(
                new ErrorMessage(400, "Failed to load scm file").addAll(errors));
    }

    ScmContentProviderParams scmParamsFromItem = getScmParamsFromItem(item);

    //if no repo param, then see if its there in given Item.
    if(repo == null && scmParamsFromItem.getRepo() == null){
        throw new ServiceException.BadRequestException("github repo could not be determine from pipeline: "+item.getFullName());
    }

    // If both, repo param and repo in pipeline scm configuration present, they better match
    if(repo != null && scmParamsFromItem.getRepo() != null && !repo.equals(scmParamsFromItem.getRepo())){
        throw new ServiceException.BadRequestException(
                String.format("repo parameter %s doesn't match with repo in pipeline %s github configuration repo: %s ",
                        repo, item.getFullName(), scmParamsFromItem.getRepo()));
    }

    if(repo == null){
        repo = scmParamsFromItem.getRepo();
    }

    ScmGetRequest scmGetRequest = new ScmGetRequest.Builder(scmParamsFromItem.getApiUrl())
            .branch(branch)
            .owner(scmParamsFromItem.getOwner())
            .repo(repo)
            .branch(branch)
            .path(path)
            .credentials(scmParamsFromItem.getCredentials()).build();

    return getContent(scmGetRequest);
}