hudson.model.Job.getProperty()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中hudson.model.Job.getProperty()方法的一些代码示例,展示了Job.getProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Job.getProperty()方法的具体详情如下:
包路径:hudson.model.Job
类名称:Job
方法名:getProperty

Job.getProperty介绍

[英]Gets the specific property, or null if the propert is not configured for this job. Supports cascading properties
[中]获取特定属性,如果未为此作业配置该属性,则为null。支持级联属性

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Standard implementation of {@link ParameterizedJob#isParameterized}.
 */
public final boolean isParameterized() {
  return asJob().getProperty(ParametersDefinitionProperty.class) != null;
}

代码示例来源:origin: jenkinsci/jenkins

@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;
}

代码示例来源:origin: jenkinsci/jenkins

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;
}

代码示例来源:origin: jenkinsci/gitlab-plugin

public static GitLabClient getClient(Run<?, ?> build) {
  final GitLabConnectionProperty connectionProperty = build.getParent().getProperty(GitLabConnectionProperty.class);
  if (connectionProperty != null) {
    return connectionProperty.getClient();
  }
  return null;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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!");
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

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);
    }
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

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();
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

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();
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

@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);
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

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);
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

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);
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

ParametersDefinitionProperty pdp = job.getProperty(ParametersDefinitionProperty.class);
if (pdp==null)
  throw new IllegalStateException(job.getFullDisplayName()+" is not parameterized but the -p option was specified.");

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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(".");
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

try {
  if (job instanceof AbstractProject<?, ?>) {
    GitLabConnectionProperty property = job.getProperty(GitLabConnectionProperty.class);

代码示例来源:origin: jenkinsci/github-plugin

@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));
    }
  }
}

代码示例来源:origin: yuzd/coding.net

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();
}

代码示例来源:origin: nishio-dens/bitbucket-pullrequest-builder-plugin

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;
}

代码示例来源:origin: jenkinsci/github-plugin

@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);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

@Override
public ACL getACL(Job<?, ?> project) {
  AuthorizationMatrixProperty amp = project.getProperty(AuthorizationMatrixProperty.class);
  if (amp != null) {
    return amp.getACL().newInheritingACL(getRootACL());
  } else {
    return getRootACL();
  }
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

@Override
public ACL getACL(Job<?,?> project) {
  AuthorizationMatrixProperty amp = project.getProperty(AuthorizationMatrixProperty.class);
  if (amp != null) {
    return amp.getACL().newInheritingACL(getRootACL());
  } else {
    return getRootACL();
  }
}

相关文章

微信公众号

最新文章

更多

Job类方法