/** * Standard implementation of {@link ParameterizedJob#isParameterized}. */ public final boolean isParameterized() { return asJob().getProperty(ParametersDefinitionProperty.class) != null; }
@Override public void onAttached(Run<?, ?> r) { ParametersDefinitionProperty p = r.getParent().getProperty(ParametersDefinitionProperty.class); if (p != null) { this.parameterDefinitionNames = new ArrayList<>(p.getParameterDefinitionNames()); } else { this.parameterDefinitionNames = Collections.emptyList(); } this.run = r; }
private List<ParameterValue> getDefaultParametersValues() { ParametersDefinitionProperty paramDefProp = asJob().getProperty(ParametersDefinitionProperty.class); ArrayList<ParameterValue> defValues = new ArrayList<ParameterValue>(); /* * This check is made ONLY if someone will call this method even if isParametrized() is false. */ if(paramDefProp == null) return defValues; /* Scan for all parameter with an associated default values */ for(ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) { ParameterValue defaultValue = paramDefinition.getDefaultParameterValue(); if(defaultValue != null) defValues.add(defaultValue); } return defValues; }
public static GitLabClient getClient(Run<?, ?> build) { final GitLabConnectionProperty connectionProperty = build.getParent().getProperty(GitLabConnectionProperty.class); if (connectionProperty != null) { return connectionProperty.getClient(); } return null; }
/** * Standard implementation of {@link ParameterizedJob#doBuildWithParameters}. */ @SuppressWarnings("deprecation") public final void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable!")); } if (pp != null) { pp.buildWithParameters(req, rsp, delay); } else { throw new IllegalStateException("This build is not parameterized!"); } }
private void setCommitStatusPendingIfNecessary(Job<?, ?> job, Integer projectId, String commit, String ref) { String buildName = PendingBuildsHandler.resolvePendingBuildName(job); if (StringUtils.isNotBlank(buildName)) { GitLabClient client = job.getProperty(GitLabConnectionProperty.class).getClient(); try { String targetUrl = DisplayURLProvider.get().getJobURL(job); client.changeBuildStatus(projectId, commit, BuildState.pending, ref, buildName, targetUrl, BuildState.pending.name()); } catch (WebApplicationException | ProcessingException e) { LOGGER.log(Level.SEVERE, "Failed to set build state to pending", e); } } }
private List<String> getProjectLabels(Job<?, ?> project) { final URIish sourceRepository = getSourceRepoURLDefault(project); GitLabConnectionProperty connectionProperty = project.getProperty(GitLabConnectionProperty.class); if (connectionProperty != null && connectionProperty.getClient() != null) { return GitLabProjectLabelsService.instance().getLabels(connectionProperty.getClient(), sourceRepository.toString()); } else { LOGGER.log(Level.WARNING, "getProjectLabels: gitlabHostUrl hasn't been configured globally. Job {0}.", project.getFullName()); return Collections.emptyList(); } }
private List<String> getProjectBranches(Job<?, ?> project) { final URIish sourceRepository = getSourceRepoURLDefault(project); GitLabConnectionProperty connectionProperty = project.getProperty(GitLabConnectionProperty.class); if (connectionProperty != null && connectionProperty.getClient() != null) { return GitLabProjectBranchesService.instance().getBranches(connectionProperty.getClient(), sourceRepository.toString()); } else { LOGGER.log(Level.WARNING, "getProjectBranches: gitlabHostUrl hasn't been configured globally. Job {0}.", project.getFullName()); return Collections.emptyList(); } }
@Override public void handle(Job<?, ?> job, PushHook hook, boolean ciSkip, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { try { if (job instanceof ParameterizedJobMixIn.ParameterizedJob) { ParameterizedJob project = (ParameterizedJobMixIn.ParameterizedJob) job; GitLabConnectionProperty property = job.getProperty(GitLabConnectionProperty.class); for (Trigger t : project.getTriggers().values()) { if (t instanceof GitLabPushTrigger) { final GitLabPushTrigger trigger = (GitLabPushTrigger) t; Integer projectId = hook.getProjectId(); if (property != null && property.getClient() != null && projectId != null && trigger != null) { GitLabClient client = property.getClient(); for (MergeRequest mergeRequest : getOpenMergeRequests(client, projectId.toString())) { if (mergeRequestLabelFilter.isMergeRequestAllowed(mergeRequest.getLabels())) { handleMergeRequest(job, hook, ciSkip, branchFilter, client, mergeRequest); } } } } } } else { LOGGER.log(Level.FINE, "Not a ParameterizedJob: {0}",LoggerUtil.toArray(job.getClass().getName())); } } catch (WebApplicationException | ProcessingException e) { LOGGER.log(Level.WARNING, "Failed to communicate with gitlab server to determine if this is an update for a merge request: " + e.getMessage(), e); } }
private void setCommitStatusCancelledIfNecessary(CauseData causeData, Job<?, ?> job) { String buildName = resolvePendingBuildName(job); if (StringUtils.isBlank(buildName)) { return; } String targetUrl = DisplayURLProvider.get().getJobURL(job); GitLabClient client = job.getProperty(GitLabConnectionProperty.class).getClient(); try { client.changeBuildStatus(causeData.getSourceProjectId(), causeData.getLastCommit(), BuildState.canceled, causeData.getSourceBranch(), buildName, targetUrl, BuildState.canceled.name()); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to set build state to pending", e); } }
private void setCommitStatusPendingIfNecessary(Job<?, ?> job, H hook) { String buildName = PendingBuildsHandler.resolvePendingBuildName(job); if (StringUtils.isNotBlank(buildName)) { GitLabClient client = job.getProperty(GitLabConnectionProperty.class).getClient(); BuildStatusUpdate buildStatusUpdate = retrieveBuildStatusUpdate(hook); try { if (client == null) { LOGGER.log(Level.SEVERE, "No GitLab connection configured"); } else { String targetUrl = DisplayURLProvider.get().getJobURL(job); client.changeBuildStatus(buildStatusUpdate.getProjectId(), buildStatusUpdate.getSha(), BuildState.pending, buildStatusUpdate.getRef(), buildName, targetUrl, BuildState.pending.name()); } } catch (WebApplicationException | ProcessingException e) { LOGGER.log(Level.SEVERE, "Failed to set build state to pending", e); } } }
ParametersDefinitionProperty pdp = job.getProperty(ParametersDefinitionProperty.class); if (pdp==null) throw new IllegalStateException(job.getFullDisplayName()+" is not parameterized but the -p option was specified.");
/** * Standard implementation of {@link ParameterizedJob#doBuild}. */ @SuppressWarnings("deprecation") public final void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { if (delay == null) { delay=new TimeDuration(TimeUnit.MILLISECONDS.convert(asJob().getQuietPeriod(), TimeUnit.SECONDS)); } if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable")); } // if a build is parameterized, let that take over ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (pp != null && !req.getMethod().equals("POST")) { // show the parameter entry form. req.getView(pp, "index.jelly").forward(req, rsp); return; } hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); if (pp != null) { pp._doBuild(req, rsp, delay); return; } Queue.Item item = Jenkins.getInstance().getQueue().schedule2(asJob(), delay.getTimeInSeconds(), getBuildCause(asJob(), req)).getItem(); if (item != null) { rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl()); } else { rsp.sendRedirect("."); } }
try { if (job instanceof AbstractProject<?, ?>) { GitLabConnectionProperty property = job.getProperty(GitLabConnectionProperty.class);
@Override public Collection<? extends Action> createFor(Job j) { GithubProjectProperty prop = ((Job<?, ?>) j).getProperty(GithubProjectProperty.class); if (prop == null) { return Collections.emptySet(); } else { return Collections.singleton(new GithubLinkAction(prop)); } } }
public static String displayNameFor(@Nonnull Job<?, ?> job) { CodingProjectProperty ghProp = job.getProperty(CodingProjectProperty.class); if (ghProp != null && isNotBlank(ghProp.getDisplayName())) { return ghProp.getDisplayName(); } return job.getFullName(); }
private Map<String, ParameterValue> getDefaultParameters() { Map<String, ParameterValue> values = new HashMap<String, ParameterValue>(); ParametersDefinitionProperty definitionProperty = this.job.getProperty(ParametersDefinitionProperty.class); if (definitionProperty != null) { for (ParameterDefinition definition : definitionProperty.getParameterDefinitions()) { values.put(definition.getName(), definition.getDefaultParameterValue()); } } return values; }
@Override public void annotate(Run<?, ?> build, Entry change, MarkupText text) { final GithubProjectProperty p = build.getParent().getProperty( GithubProjectProperty.class); if (null == p) { return; } annotate(p.getProjectUrl(), text, change); }
@Override public ACL getACL(Job<?, ?> project) { AuthorizationMatrixProperty amp = project.getProperty(AuthorizationMatrixProperty.class); if (amp != null) { return amp.getACL().newInheritingACL(getRootACL()); } else { return getRootACL(); } }
@Override public ACL getACL(Job<?,?> project) { AuthorizationMatrixProperty amp = project.getProperty(AuthorizationMatrixProperty.class); if (amp != null) { return amp.getACL().newInheritingACL(getRootACL()); } else { return getRootACL(); } }