Ejemplo n.º 1
0
  @Override
  public Environment setUp(final AbstractBuild build, Launcher launcher, BuildListener listener)
      throws IOException, InterruptedException {
    final String artifactoryServerName = getArtifactoryName();
    if (StringUtils.isBlank(artifactoryServerName)) {
      return super.setUp(build, launcher, listener);
    }
    final ArtifactoryServer artifactoryServer = getArtifactoryServer();
    if (artifactoryServer == null) {
      listener
          .getLogger()
          .format(
              "[JFROG] No Artifactory server configured for %s. "
                  + "Please check your configuration.",
              artifactoryServerName)
          .println();
      build.setResult(Result.FAILURE);
      throw new IllegalArgumentException(
          "No Artifactory server configured for " + artifactoryServerName);
    }

    Credentials preferredDeployer;
    ArtifactoryServer server = getArtifactoryServer();
    if (isOverridingDefaultDeployer()) {
      preferredDeployer = getOverridingDeployerCredentials();
    } else {
      preferredDeployer = server.getResolvingCredentials();
    }

    hudson.ProxyConfiguration proxy = Hudson.getInstance().proxy;
    ProxyConfiguration proxyConfiguration = null;
    if (proxy != null && proxy.getName() != null) {
      proxyConfiguration = new ProxyConfiguration();
      proxyConfiguration.host = proxy.name;
      proxyConfiguration.port = proxy.port;
      proxyConfiguration.username = proxy.getUserName();
      proxyConfiguration.password = proxy.getPassword();
    }
    ArtifactoryDependenciesClient dependenciesClient =
        server.createArtifactoryDependenciesClient(
            preferredDeployer.getUsername(),
            preferredDeployer.getPassword(),
            proxyConfiguration,
            listener);
    try {
      GenericArtifactsResolver artifactsResolver =
          new GenericArtifactsResolver(build, listener, dependenciesClient, getResolvePattern());
      publishedDependencies = artifactsResolver.retrievePublishedDependencies();
      buildDependencies = artifactsResolver.retrieveBuildDependencies();

      return createEnvironmentOnSuccessfulSetup();
    } catch (Exception e) {
      e.printStackTrace(listener.error(e.getMessage()));
    } finally {
      dependenciesClient.shutdown();
    }

    return null;
  }
Ejemplo n.º 2
0
 public ArtifactoryServer getArtifactoryServer() {
   List<ArtifactoryServer> servers = getDescriptor().getArtifactoryServers();
   for (ArtifactoryServer server : servers) {
     if (server.getName().equals(getArtifactoryName())) {
       return server;
     }
   }
   return null;
 }