public BuildFinishedStatus runProcess()

in deploy-runner-agent-smb2/src/main/java/jetbrains/buildServer/deployer/agent/smb/SMBJBuildProcessAdapter.java [74:148]


  public BuildFinishedStatus runProcess() {
    String target;
    if (myTarget.startsWith("\\\\")) {
      target = myTarget.substring(2);
    } else {
      target = myTarget;
    }

    target = target.replaceAll("/", java.util.regex.Matcher.quoteReplacement("\\"));
    if (!target.endsWith("\\")) {
      target = target + "\\";
    }

    final String settingsString = "Trying to connect with following parameters:\n" +
            "username=[" + myUsername + "]\n" +
            "domain=[" + (myDomain == null ? "" : myDomain) + "]\n" +
            "target=[" + target + "]";

    Loggers.AGENT.debug(settingsString);
    myLogger.message("Starting upload via SMBj to " + myTarget);

    final List<String> components = StringUtil.split(target, "\\");
    final String host = components.remove(0);
    final String shareName = components.size() > 0 ? components.remove(0) : "";
    final String pathInShare = StringUtil.join(components, "\\");

    try {
      SmbConfig.Builder config = SmbConfig
              .builder()
              .withMultiProtocolNegotiate(true)
              .withSigningRequired(true);

      if (!TeamCityProperties.getBoolean("teamcity.plugin.deployer.use_jce"))
        config = config.withSecurityProvider(new BCSecurityProvider());

      SMBClient client = new SMBClient(config.build());

      Connection connection = client.connect(host);
      Session session = connection.authenticate(new AuthenticationContext(myUsername, myPassword.toCharArray(), myDomain));
      Share share = session.connectShare(shareName);

      if (share instanceof DiskShare) {
        DiskShare diskShare = (DiskShare)share;
        for (ArtifactsCollection artifactsCollection : myArtifactsCollections) {
          final int numOfUploadedFiles = upload(artifactsCollection.getFilePathMap(), diskShare, pathInShare);
          myLogger.message("Uploaded [" + numOfUploadedFiles + "] files for [" + artifactsCollection.getSourcePath() + "] pattern");
        }

      } else {
        logBuildProblem(myLogger, "Shared resource [" + shareName + "] is not a folder, can not upload files.");
        return BuildFinishedStatus.FINISHED_FAILED;
      }

      return BuildFinishedStatus.FINISHED_SUCCESS;
    } catch (TransportException e) {

      final String message;
      if (hasCauseOfType(SMB1NotSupportedException.class, e)) {
        message = "The remote host [" + host + "] does not support SMBv2 or support was explicitly disabled. Please, check the remote host configuration";
      } else {
        message = e.getMessage();
      }
      logBuildProblem(myLogger, message);

      LOG.warnAndDebugDetails("Error executing SMB command", e);
      return BuildFinishedStatus.FINISHED_FAILED;
    } catch (UploadInterruptedException e) {
      myLogger.warning("SMB upload interrupted.");
      return BuildFinishedStatus.FINISHED_FAILED;
    } catch (IOException | SMBRuntimeException e) {
      logBuildProblem(myLogger, e.getMessage());
      LOG.warnAndDebugDetails("Error executing SMB command", e);
      return BuildFinishedStatus.FINISHED_FAILED;
    }
  }