Search in sources :

Example 51 with Jenkins

use of jenkins.model.Jenkins in project selenium_java by sergueik.

the class JobsByDateReportImpl method getProjectExecutions.

@Override
public Map<String, List<BuildDetails>> getProjectExecutions(final String startDateString, final String endDateString) {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins != null) {
        // unit tests won't have a Jenkins instance
        jenkins.checkPermission(DbAuditPlugin.RUN);
    }
    final Map<String, List<BuildDetails>> retval = new HashMap<String, List<BuildDetails>>();
    final Date startDate = DbAuditReportUtils.stringToDate(startDateString);
    final Date endDate = DbAuditReportUtils.stringToDate(endDateString);
    final String jenkinsHost = getJenkinsHostname();
    final List<String> projectNames = getRepository().getProjectNames(jenkinsHost, startDate, endDate);
    for (final String projectName : projectNames) {
        final List<BuildDetails> buildDetails = getRepository().getBuildDetails(jenkinsHost, projectName, startDate, endDate);
        if (!buildDetails.isEmpty()) {
            retval.put(projectName, buildDetails);
        }
    }
    return retval;
}
Also used : Jenkins(jenkins.model.Jenkins) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HashMap(java.util.HashMap) List(java.util.List) Date(java.util.Date)

Example 52 with Jenkins

use of jenkins.model.Jenkins in project selenium_java by sergueik.

the class JobsByParamReportImpl method getProjectExecutions.

/**
 * @see org.jenkins.plugins.audit2db.reports.JobsByParamReport#getProjectExecutions(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public Map<String, List<BuildDetails>> getProjectExecutions(final String paramName, final String paramValue, final String startDateString, final String endDateString) {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins != null) {
        // unit tests won't have a Jenkins instance
        jenkins.checkPermission(DbAuditPlugin.RUN);
    }
    final Map<String, List<BuildDetails>> retval = new HashMap<String, List<BuildDetails>>();
    final Date startDate = DbAuditReportUtils.stringToDate(startDateString);
    final Date endDate = DbAuditReportUtils.stringToDate(endDateString);
    final String jenkinsHost = getJenkinsHostname();
    final List<BuildDetails> buildDetails = getRepository().getBuildDetailsByParams(jenkinsHost, paramName, paramValue, startDate, endDate);
    for (final BuildDetails details : buildDetails) {
        final String projectName = details.getName();
        if (!retval.containsKey(projectName)) {
            retval.put(projectName, new ArrayList<BuildDetails>());
        }
        retval.get(projectName).add(details);
    }
    return retval;
}
Also used : Jenkins(jenkins.model.Jenkins) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date)

Example 53 with Jenkins

use of jenkins.model.Jenkins in project selenium_java by sergueik.

the class BuildDetailsResolver method addBuildNodeFromContext.

private static void addBuildNodeFromContext(BuildDetailsImpl details, Run<?, ?> run, Computer computer) throws IOException, InterruptedException {
    LOGGER.finer("resolving build node");
    Jenkins jenkins = Jenkins.getInstance();
    LOGGER.finer("jenkins: " + jenkins);
    LOGGER.finer("computer: " + computer);
    Node node = computer.getNode();
    LOGGER.finer("node: " + node);
    String rootUrl = jenkins != null ? jenkins.getRootUrl() : "http://unconfigured-jenkins-server/";
    LOGGER.finer("rootUrl: " + rootUrl);
    URL url = new URL(rootUrl);
    String masterHostname = url.getHost();
    String urlString = String.format("%s/%s", rootUrl, computer.getUrl()).replaceAll("(\\w)(\\/{2,})(\\w)", "$1/$3");
    BuildNode buildNode = new BuildNodeImpl(resolveMasterIpAddress(computer), masterHostname, computer.getDisplayName(), // url
    urlString, node.getNodeName(), node.getNodeDescription(), node.getLabelString());
    LOGGER.finer("buildNode: " + buildNode);
    details.setNode(buildNode);
}
Also used : Jenkins(jenkins.model.Jenkins) BuildNodeImpl(org.jenkins.plugins.audit2db.internal.model.BuildNodeImpl) Node(hudson.model.Node) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode) URL(java.net.URL) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode)

Example 54 with Jenkins

use of jenkins.model.Jenkins in project sonar-scanner-jenkins by SonarSource.

the class SonarGlobalConfiguration method migrate.

/**
 * Attempts to migrated data from SonarPublished, which was previously holding the global configuration.
 * It is thread safe and will refuse to migrate if a SonarQube installation already exists in this class.
 * Migration will only be attempted once.
 */
@Initializer(after = InitMilestone.PLUGINS_PREPARED)
public void migrate() {
    if (migrated) {
        return;
    }
    synchronized (this) {
        if (migrated) {
            return;
        }
        // SonarPublisher might be null if Maven plugin is disabled or not installed
        Jenkins j = Jenkins.getInstance();
        DescriptorImpl publisher = j.getDescriptorByType(SonarPublisher.DescriptorImpl.class);
        if (publisher != null && publisher.getDeprecatedInstallations() != null && publisher.getDeprecatedInstallations().length > 0) {
            if (ArrayUtils.isEmpty(this.installations)) {
                this.installations = publisher.getDeprecatedInstallations();
                this.buildWrapperEnabled = publisher.isDeprecatedBuildWrapperEnabled();
                save();
            } else {
                Logger.LOG.warning("SonarQube server configurations exist in both deprecated SonarPublisher and SonarGlobalConfiguration. Deleting deprecated configuration..");
            }
            publisher.deleteGlobalConfiguration();
        }
        migrated = true;
    }
}
Also used : Jenkins(jenkins.model.Jenkins) DescriptorImpl(hudson.plugins.sonar.SonarPublisher.DescriptorImpl) Initializer(hudson.init.Initializer)

Example 55 with Jenkins

use of jenkins.model.Jenkins in project sonar-scanner-jenkins by SonarSource.

the class SonarInstallation method all.

/**
 * @return all available installations, never <tt>null</tt> but can be empty.
 * @since 1.7
 */
public static final SonarInstallation[] all() {
    Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        // for unit test
        return new SonarInstallation[0];
    }
    SonarGlobalConfiguration sonarDescriptor = jenkins.getDescriptorByType(SonarGlobalConfiguration.class);
    return sonarDescriptor.getInstallations();
}
Also used : Jenkins(jenkins.model.Jenkins)

Aggregations

Jenkins (jenkins.model.Jenkins)73 Test (org.junit.Test)22 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)13 IOException (java.io.IOException)10 File (java.io.File)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 Statement (org.junit.runners.model.Statement)7 CheckForNull (javax.annotation.CheckForNull)6 FilePath (hudson.FilePath)5 Computer (hudson.model.Computer)5 URL (java.net.URL)5 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)5 Issue (org.jvnet.hudson.test.Issue)5 Item (hudson.model.Item)4 Node (hudson.model.Node)4 Date (java.util.Date)4