jetbrains.buildServer.agent.BuildRunnerContext Java Examples

The following examples show how to use jetbrains.buildServer.agent.BuildRunnerContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SMBBuildProcessAdapter.java    From teamcity-deployer-plugin with Apache License 2.0 6 votes vote down vote up
public SMBBuildProcessAdapter(@NotNull final BuildRunnerContext context,
                              @NotNull final String username,
                              @NotNull final String password,
                              @Nullable final String domain,
                              @NotNull final String target,
                              @NotNull final List<ArtifactsCollection> artifactsCollections,
                              final boolean dnsOnlyNameResolution) {
  super(context.getBuild().getBuildLogger());
  myTarget = target;
  myUsername = username;
  myPassword = password;
  myDomain = domain;
  myArtifactsCollections = artifactsCollections;

  jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords", "false");
  if (dnsOnlyNameResolution) {
    jcifs.Config.setProperty("jcifs.resolveOrder", "DNS");
    jcifs.Config.setProperty("jcifs.smb.client.dfs.disabled", "true");
  }
}
 
Example #2
Source File: FtpDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context,
                                          @NotNull final String username,
                                          @NotNull final String password,
                                          @NotNull final String target,
                                          @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException {
  final Map<String, String> runnerParameters = context.getRunnerParameters();
  final String authMethod = runnerParameters.get(FTPRunnerConstants.PARAM_AUTH_METHOD);

  if (FTPRunnerConstants.AUTH_METHOD_USER_PWD.equals(authMethod)) {
    return new FtpBuildProcessAdapter(context, target, username, password, artifactsCollections);
  } else if (FTPRunnerConstants.AUTH_METHOD_ANONYMOUS.equals(authMethod)) {
    return new FtpBuildProcessAdapter(context, target, "anonymous", " ", artifactsCollections);
  } else {
    throw new RunBuildException("Unknown FTP authentication method: [" + authMethod + "]");
  }

}
 
Example #3
Source File: FtpBuildProcessAdapter.java    From teamcity-deployer-plugin with Apache License 2.0 6 votes vote down vote up
private FtpConnectTimeout getConnectTimeout(BuildRunnerContext context) {
  String timeout = context.getBuild().getSharedConfigParameters().get(FTPRunnerConstants.PARAM_FTP_CONNECT_TIMEOUT);
  if (timeout == null || timeout.isEmpty()) {
    return new FtpConnectTimeout();
  }

  String[] timeouts = timeout.split(" ");
  try {
    if (timeouts.length == 1) {
      return new FtpConnectTimeout(getTimeoutFromString(timeout));
    } else if (timeouts.length == 3) {
      return new FtpConnectTimeout(getTimeoutFromString(timeouts[0]),
                                   getTimeoutFromString(timeouts[1]),
                                   getTimeoutFromString(timeouts[2]));
    }
  } catch (NumberFormatException err) {
    //
  }

  LOG.warn("Incorrect format of ftp connect timeout '" + timeout + "'. " +
                   "Expecting either single value integer either three integers for " +
                   "1. socketTimeout  2. connectTimeout  3. dataTimeout. " +
                   "Default value " + DEFAULT_FTP_CONNECT_TIMEOUT  + "ms was used for 2. and 3.");
  return new FtpConnectTimeout();
}
 
Example #4
Source File: CommandlineBuildProcessFactoryImpl.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@NotNull
public BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,
                                       @NotNull Collection<String> argz,
                                       @NotNull File workingDir,
                                       @NotNull final Map<String, String> additionalEnvironment) throws RunBuildException {
  BuildRunnerContext context = myFacade.createBuildRunnerContext(
          hostContext.getBuild(),
          SimpleRunnerConstants.TYPE,
          workingDir.getPath(),
          hostContext
  );

  for (Map.Entry<String, String> entry : additionalEnvironment.entrySet()) {
    context.addEnvironmentVariable(entry.getKey(), entry.getValue());
  }

  final List<String> newArgz = new ArrayList<String>(argz);
  final String commandLine = joinCommandLineArguments(newArgz);

  hostContext.getBuild().getBuildLogger().message("Executing command: " + commandLine);

  context.addRunnerParameter(SimpleRunnerConstants.USE_CUSTOM_SCRIPT, "true");
  context.addRunnerParameter(SimpleRunnerConstants.SCRIPT_CONTENT, commandLine);

  return myFacade.createExecutable(hostContext.getBuild(), context);
}
 
Example #5
Source File: SSHDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context,
                                          @NotNull final String username,
                                          @NotNull final String password,
                                          @NotNull final String target,
                                          @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException {

  final SSHSessionProvider provider = new SSHSessionProvider(context, myInternalProperties, mySshKeyManager);
  final String transport = context.getRunnerParameters().get(SSHRunnerConstants.PARAM_TRANSPORT);
  if (SSHRunnerConstants.TRANSPORT_SCP.equals(transport)) {
    return new ScpProcessAdapter(context, artifactsCollections, provider);
  } else if (SSHRunnerConstants.TRANSPORT_SFTP.equals(transport)) {
    return new SftpBuildProcessAdapter(context, artifactsCollections, provider);
  } else {
    throw new RunBuildException("Unknown ssh transport [" + transport + "]");
  }
}
 
Example #6
Source File: AnsibleOutputListener.java    From tc-ansible-runner with MIT License 6 votes vote down vote up
public AnsibleOutputListener(AgentRunningBuild build, BuildRunnerContext buildRunnerContext, ArtifactsWatcher artifactsWatcher) {
    this.artifactsWatcher = artifactsWatcher;
    this.buildRunnerContext = buildRunnerContext;
    File tmpDir = new File(build.getBuildTempDirectory(), "ansible-run");
    boolean exists = tmpDir.exists(); 
    if (!exists) {
        exists = tmpDir.mkdir();
    }
    if (!exists) {
        LOG.error("Cannot create a directory " + tmpDir.getAbsolutePath() + " for ansible run raw output storage");
        build.getBuildLogger().warning("Cannot create a directory for ansible run raw output storage. Ansible report will not be generated");
    } else {
        String rawFileName = "ansible-run-raw-" + buildRunnerContext.getId() + ".log";
        rawFile = new File(tmpDir, rawFileName);
        try {
            rawFile.createNewFile();
        } catch (IOException e) {
            LOG.error("Cannot create a file " + rawFileName + " for ansible run raw output writing ", e);
            build.getBuildLogger().warning("Cannot create a file for ansible run raw output writing. Ansible report will not be generated");
        }
        build.addSharedConfigParameter(AnsibleRunnerConstants.ARTIFACTS_TMP_DIR_KEY, tmpDir.getAbsolutePath());
    }
}
 
Example #7
Source File: AllureToolProvider.java    From allure-teamcity with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@NotNull
@Override
public String getPath(@NotNull final String toolName,
                      @NotNull final AgentRunningBuild build,
                      @NotNull final BuildRunnerContext runner) {
    return runner.getRunnerParameters().get(AllureConstants.ALLURE_TOOL_VERSION);
}
 
Example #8
Source File: SMBJBuildProcessAdapter.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused") // used via reflection
public SMBJBuildProcessAdapter(@NotNull final BuildRunnerContext context,
                               @NotNull final String username,
                               @NotNull final String password,
                               @Nullable final String domain,
                               @NotNull final String target,
                               @NotNull final List<ArtifactsCollection> artifactsCollections) {
  super(context.getBuild().getBuildLogger());
  myTarget = target;
  myUsername = username;
  myPassword = password;
  myDomain = domain;
  myArtifactsCollections = artifactsCollections;
}
 
Example #9
Source File: VMRunnerFactory.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@NotNull
private VMRunner getVMBuildProcess(@NotNull final BuildRunnerContext context) throws RunBuildException {
  final String vm = context.getRunnerParameters().get(VMConstants.PARAMETER_VM);
  for (VMRunner runner : myRunners) {
    if (runner.getVMName().equals(vm)) {
      return runner;
    }
  }

  throw new RunBuildException("Parameter " + VMConstants.PARAMETER_VM + " in invalid: " + vm);
}
 
Example #10
Source File: ExecutionChain.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Executable modify(@NotNull final Executable old, final BuildRunnerContext runnerContext) {
    Executable current = old;
    for (Execution execution : myChain) {
        current = execution.modify(current, runnerContext);
    }
    return current;
}
 
Example #11
Source File: SonarQubeArgumentsWrapper.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Executable modify(@NotNull final Executable old,
                         @NotNull final BuildRunnerContext runnerContext) {
    final SQRParametersAccessor accessor = mySQRParametersAccessorFactory.createAccessor(runnerContext);

    final List<String> args = mySQArgsComposer.composeArgs(accessor, new DotNetSonarQubeKeysProvider());
    final List<String> res = new ArrayList<String>(old.myArguments);
    res.addAll(args);

    return new Executable(old.myExecutable, res);
}
 
Example #12
Source File: SQMSBuildStartServiceFactory.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Executable modify(@NotNull final Executable old, final BuildRunnerContext runnerContext) {
    final ArrayList<String> arguments = new ArrayList<String>(old.myArguments);
    arguments.add("begin");
    return new Executable(old.myExecutable, arguments);
}
 
Example #13
Source File: SQMSBuildStartServiceFactory.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
public SQMSBuildStartServiceFactory(@NotNull final SQMSBuildStartRunner sqmsBuildStartRunner,
                                    @NotNull final OSType osType,
                                    @NotNull final MonoLocator monoLocator,
                                    @NotNull final SQMSBuildFinishServiceFactory sqmsBuildFinishServiceFactory,
                                    @NotNull final EventDispatcher<AgentLifeCycleListener> dispatcher) {
    mySQMSBuildStartRunner = sqmsBuildStartRunner;
    myOSType = osType;
    myMonoLocator = monoLocator;
    mySqmsBuildFinishServiceFactory = sqmsBuildFinishServiceFactory;
    mySonarQubeMSBuildScannerLocator = new SonarQubeMSBuildScannerLocatorImpl();

    dispatcher.addListener(new AgentLifeCycleAdapter() {
        @Override
        public void beforeRunnerStart(@NotNull final BuildRunnerContext runner) {
            if (runner.getRunType().equals(mySQMSBuildStartRunner.getType())) {

                mySqmsBuildFinishServiceFactory.setUpFinishStep(new SonarQubeMSBuildScannerLocator() {
                    @Nullable
                    @Override
                    public String getExecutablePath(@NotNull final BuildRunnerContext runnerContext) throws RunBuildException {
                        return mySonarQubeMSBuildScannerLocator.getExecutablePath(runner);
                    }
                }, runner.getWorkingDirectory(), new SQRParametersAccessor(SQRParametersUtil.mergeAuthParameters(runner.getBuild().getSharedConfigParameters(), runner.getRunnerParameters())));
            }
        }
    });
}
 
Example #14
Source File: MonoWrapper.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Executable modify(@NotNull final Executable old, final BuildRunnerContext runnerContext) {
    if (myOSType != OSType.WINDOWS) {
        final List<String> newArgs = new ArrayList<String>(old.myArguments.size() + 1);
        newArgs.add(old.myExecutable);
        newArgs.addAll(old.myArguments);
        return new Executable(myMonoLocator.getMono(), newArgs);
    } else {
        return old;
    }
}
 
Example #15
Source File: SQMSBuildExecutableFactory.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Executable create(@NotNull final BuildRunnerContext runnerContext) throws RunBuildException {
    final String msBuildScannerRoot = mySonarQubeMSBuildScannerLocator.getExecutablePath(runnerContext);

    if (msBuildScannerRoot == null) {
        throw new RunBuildException("No SonarScanner for MSBuild selected");
    }

    final File executableFile = new File(msBuildScannerRoot, "MSBuild.SonarQube.Runner.exe");

    checkExecutable(executableFile);

    return new Executable(executableFile.getAbsolutePath(), Collections.<String>emptyList());
}
 
Example #16
Source File: FtpBuildProcessAdapter.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
public FtpBuildProcessAdapter(@NotNull final BuildRunnerContext context,
                              @NotNull final String target,
                              @NotNull final String username,
                              @NotNull final String password,
                              @NotNull final List<ArtifactsCollection> artifactsCollections) {
  super(context.getBuild().getBuildLogger());
  myIsActive = "ACTIVE".equals(context.getRunnerParameters().get(FTPRunnerConstants.PARAM_FTP_MODE));
  myTarget = target.toLowerCase().startsWith(FTP_PROTOCOL) ? target : FTP_PROTOCOL + target;
  myUsername = username;
  myPassword = password;
  myArtifacts = artifactsCollections;
  myTransferMode = context.getRunnerParameters().get(FTPRunnerConstants.PARAM_TRANSFER_MODE);
  mySecureMode = context.getRunnerParameters().get(FTPRunnerConstants.PARAM_SSL_MODE);
  myFtpConnectTimeout = getConnectTimeout(context);
}
 
Example #17
Source File: SmbDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context,
                                          @NotNull final String username,
                                          @NotNull final String password,
                                          @NotNull final String target,
                                          @NotNull final List<ArtifactsCollection> artifactsCollections) {

  try {
    final String domain;
    final String actualUsername;

    if (username.indexOf('\\') > -1) {
      domain = username.substring(0, username.indexOf('\\'));
      actualUsername = username.substring(username.indexOf('\\') + 1);
    } else {
      domain = "";
      actualUsername = username;
    }

    if (shouldEnforceSMBv1(context)) {
      context.getBuild().getBuildLogger().warning("Enforced deprecated SMB v1 usage");
      return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections);
    }

    if (SystemInfo.isJavaVersionAtLeast("1.7.0")) {
        context.getBuild().getBuildLogger().message("Using SMB v2/v3 protocol");
        return getSmbV2Process(context, actualUsername, password, domain, target,artifactsCollections);
    } else {
      context.getBuild().getBuildLogger().warning("Falling back to deprecated SMB v1. Update jvm to 1.7+ to use SMB v2");
      return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections);
    }

  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #18
Source File: SSHSessionProvider.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
public SSHSessionProvider(@NotNull final BuildRunnerContext context,
                          @NotNull final InternalPropertiesHolder holder,
                          @NotNull final AgentRunningBuildSshKeyManager sshKeyManager) {
  mySshKeyManager = sshKeyManager;

  final String target = context.getRunnerParameters().get(DeployerRunnerConstants.PARAM_TARGET_URL);
  final String portStr = context.getRunnerParameters().get(SSHRunnerConstants.PARAM_PORT);
  try {
    myPort = Integer.parseInt(portStr);
  } catch (NumberFormatException e) {
    myPort = 22;
  }

  final int delimiterIndex = target.indexOf(':');
  if (delimiterIndex > 0) {
    myHost = target.substring(0, delimiterIndex);
    final String remotePath = target.substring(delimiterIndex + 1);

    myRemotePath = remotePath.trim().replaceAll("\\\\", "/");
    if (new File(myRemotePath).isAbsolute() && !myRemotePath.startsWith("/")) {
      myRemotePath = "/" + myRemotePath;
    }
  } else {
    myHost = target;
    myRemotePath = "";
  }

  myContext = context;
  myHolder = holder;
}
 
Example #19
Source File: SftpBuildProcessAdapter.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
public SftpBuildProcessAdapter(@NotNull final BuildRunnerContext context,
                               @NotNull final List<ArtifactsCollection> artifactsCollections,
                               @NotNull final SSHSessionProvider sessionProvider) {
  super(context.getBuild().getBuildLogger());
  myArtifacts = artifactsCollections;
  mySessionProvider = sessionProvider;
}
 
Example #20
Source File: ScpProcessAdapter.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
public ScpProcessAdapter(@NotNull final BuildRunnerContext context,
                         @NotNull final List<ArtifactsCollection> artifactsCollections,
                         @NotNull final SSHSessionProvider sessionProvider) {
  super(context.getBuild().getBuildLogger());
  myArtifacts = artifactsCollections;
  mySessionProvider = sessionProvider;

}
 
Example #21
Source File: CargoBuildProcessAdapter.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
public CargoBuildProcessAdapter(@NotNull String target,
                                @NotNull String username,
                                @NotNull String password,
                                @NotNull BuildRunnerContext context,
                                @NotNull String sourcePath) {
  super(context.getBuild().getBuildLogger());
  myHost = getHost(target);
  myPort = getPort(target);
  myUsername = username;
  myPassword = password;
  myContext = context;
  mySourcePath = sourcePath;
  myContainerType = context.getRunnerParameters().get(DeployerRunnerConstants.PARAM_CONTAINER_TYPE);
  myUseHttps = Boolean.valueOf(context.getRunnerParameters().get(CargoRunnerConstants.USE_HTTPS));
}
 
Example #22
Source File: SmbDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
private BuildProcess getSmbV1Process(@NotNull final BuildRunnerContext context,
                                     @NotNull final String username,
                                     @NotNull final String password,
                                     @NotNull final String domain,
                                     @NotNull final String target,
                                     @NotNull final List<ArtifactsCollection> artifactsCollections) throws Exception {
  final ClassLoader processClassloader = loadClassesFrom("smbLib");
  final Class smbBuildProcessClass = processClassloader.loadClass("jetbrains.buildServer.deployer.agent.smb.SMBBuildProcessAdapter");

  final boolean dnsOnly = Boolean.valueOf(context.getRunnerParameters().get(SMBRunnerConstants.DNS_ONLY_NAME_RESOLUTION));

  final Constructor constructor = smbBuildProcessClass.getConstructor(BuildRunnerContext.class,
          String.class, String.class, String.class, String.class, List.class, boolean.class);
  return (BuildProcess) constructor.newInstance(context, username, password, domain, target, artifactsCollections, dnsOnly);
}
 
Example #23
Source File: SmbDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
private BuildProcess getSmbV2Process(@NotNull final BuildRunnerContext context,
                                     @NotNull final String username,
                                     @NotNull final String password,
                                     @NotNull final String domain,
                                     @NotNull final String target,
                                     @NotNull final List<ArtifactsCollection> artifactsCollections) throws Exception {
  final ClassLoader processClassloader = loadClassesFrom("smb2Lib");
  final Class smbBuildProcessClass = processClassloader.loadClass("jetbrains.buildServer.deployer.agent.smb.SMBJBuildProcessAdapter");
  final Constructor constructor = smbBuildProcessClass.getConstructor(BuildRunnerContext.class,
          String.class, String.class, String.class, String.class, List.class);
  return (BuildProcess) constructor.newInstance(context, username, password, domain, target, artifactsCollections);
}
 
Example #24
Source File: SmbDeployerRunner.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
private boolean shouldEnforceSMBv1(@NotNull final BuildRunnerContext context) {
  boolean shouldEnforceOnBuild =
          StringUtil.isTrue(context.getBuild().getSharedConfigParameters().get(SMBRunnerConstants.SHOULD_ENFORCE_SMB1));
  if (shouldEnforceOnBuild) {
    return true;
  }

  return TeamCityProperties.getBoolean(SMBRunnerConstants.SHOULD_ENFORCE_SMB1);
}
 
Example #25
Source File: Execution.java    From TeamCity.SonarQubePlugin with Apache License 2.0 4 votes vote down vote up
@NotNull
Executable modify(@NotNull Executable old, final BuildRunnerContext runnerContext);
 
Example #26
Source File: VagrantContext.java    From TeamCity.Virtual with Apache License 2.0 4 votes vote down vote up
public VagrantContext(@NotNull final BuildRunnerContext context) {
  super(context);
}
 
Example #27
Source File: VMRunnerContext.java    From TeamCity.Virtual with Apache License 2.0 4 votes vote down vote up
public VMRunnerContext(@NotNull final BuildRunnerContext context) {
  myContext = context;
}
 
Example #28
Source File: DockerContext.java    From TeamCity.Virtual with Apache License 2.0 4 votes vote down vote up
public DockerContext(@NotNull final BuildRunnerContext context) {
  super(context);
}
 
Example #29
Source File: CommandlineBuildProcessFactory.java    From TeamCity.Virtual with Apache License 2.0 4 votes vote down vote up
@NotNull
BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,
                                @NotNull Collection<String> argz,
                                @NotNull File workingDir,
                                @NotNull Map<String, String> additionalEnvironment) throws RunBuildException;
 
Example #30
Source File: ExecutableFactory.java    From TeamCity.SonarQubePlugin with Apache License 2.0 4 votes vote down vote up
@NotNull
Executable create(@NotNull final BuildRunnerContext runnerContext) throws RunBuildException;