@Override @NotNull public TaskResult execute(@NotNull CommonTaskContext commonTaskContext) throws TaskException { final TaskResultBuilder taskResultBuilder = TaskResultBuilder.newBuilder(commonTaskContext); final TaskContext taskContext = Narrow.to(commonTaskContext, TaskContext.class); final BuildLogger buildLogger = taskContext.getBuildLogger(); // move this crazy resolution out of here. resolveContext(taskContext, commonTaskContext); final String rubyRuntimeLabel = RubyBuildConfigurationPlugin.getRubyRuntime(getBuildDefinition()); try { if (rubyRuntimeLabel == null) { throw new RuntimeLocatorException( "A ruby runtime has not been chosen for this plan. Please see the miscellaneous tab to choose a plan-wide ruby runtime."); } final RubyLabel rubyLabel = RubyLabel.fromString(rubyRuntimeLabel); final ConfigurationMap config = commonTaskContext.getConfigurationMap(); Map<String, String> envVars = buildEnvironment(rubyLabel, config); List<String> commandsList = buildCommandList(rubyLabel, config); ExternalProcess externalProcess = getProcessService() .createExternalProcess( commonTaskContext, new ExternalProcessBuilder() .env(envVars) .command(commandsList) .workingDirectory(commonTaskContext.getWorkingDirectory())); externalProcess.execute(); taskResultBuilder.checkReturnCode(externalProcess, 0); } catch (IllegalArgumentException e) { buildLogger.addErrorLogEntry("Could not run ruby task: " + e.getMessage(), e); taskResultBuilder.failed(); } catch (PathNotFoundException e) { buildLogger.addErrorLogEntry("Could not run ruby task: " + e.getMessage(), e); taskResultBuilder.failed(); } catch (RuntimeLocatorException e) { buildLogger.addErrorLogEntry("Could not run ruby task: " + e.getMessage(), e); taskResultBuilder.failed(); } return taskResultBuilder.build(); }
@NotNull @Override public TaskResult execute(@NotNull DeploymentTaskContext deploymentTaskContext) throws TaskException { buildLogger = deploymentTaskContext.getBuildLogger(); ServerConfigManager serverConfigManager = ServerConfigManager.getInstance(); String serverId = deploymentTaskContext .getConfigurationMap() .get( ArtifactoryDeploymentConfiguration.DEPLOYMENT_PREFIX + AbstractBuildContext.SERVER_ID_PARAM); if (StringUtils.isBlank(serverId)) { // Compatibility with version 1.8.0 serverId = deploymentTaskContext.getConfigurationMap().get("artifactoryServerId"); } ServerConfig serverConfig = serverConfigManager.getServerConfigById(Long.parseLong(serverId)); if (serverConfig == null) { buildLogger.addErrorLogEntry( "Could not find Artifactpry server. Please check the Artifactory server in the task configuration."); return TaskResultBuilder.newBuilder(deploymentTaskContext).failedWithError().build(); } repositoryKey = deploymentTaskContext .getConfigurationMap() .get( ArtifactoryDeploymentConfiguration.DEPLOYMENT_PREFIX + ArtifactoryDeploymentConfiguration.DEPLOYMENT_REPOSITORY); if (StringUtils.isBlank(repositoryKey)) { // Compatibility with version 1.8.0 repositoryKey = deploymentTaskContext .getConfigurationMap() .get(ArtifactoryDeploymentConfiguration.DEPLOYMENT_REPOSITORY); } artifactsRootDirectory = deploymentTaskContext.getRootDirectory().getAbsolutePath(); // Get the deployer credentials configured in the task configuration String username = deploymentTaskContext .getConfigurationMap() .get( ArtifactoryDeploymentConfiguration.DEPLOYMENT_PREFIX + ArtifactoryDeploymentConfiguration.USERNAME); String password = deploymentTaskContext .getConfigurationMap() .get( ArtifactoryDeploymentConfiguration.DEPLOYMENT_PREFIX + ArtifactoryDeploymentConfiguration.PASSWORD); // If deployer credentials were not configured in the task configuration, use the credentials // configured // globally if (StringUtils.isBlank(username) && StringUtils.isBlank(password)) { username = serverConfig.getUsername(); password = serverConfig.getPassword(); } TaskResult result; client = new ArtifactoryBuildInfoClient( serverConfig.getUrl(), username, password, new BuildInfoLog(log)); try { RuntimeTaskDefinition artifactDownloadTask = TaskUtils.findDownloadArtifactsTask( deploymentTaskContext.getCommonContext().getRuntimeTaskDefinitions()); FilesCollector filesCollector = new FilesCollector(artifactsRootDirectory, artifactDownloadTask); Map<String, Set<File>> artifacts = filesCollector.getCollectedFiles(); Set<DeployDetails> deployDetailsSet = createDeploymentDetailsForArtifacts(artifacts); deploy(deployDetailsSet); result = TaskResultBuilder.newBuilder(deploymentTaskContext).success().build(); } catch (Exception e) { buildLogger.addErrorLogEntry( "Error while deploying artifacts to Artifactory: " + e.getMessage()); result = TaskResultBuilder.newBuilder(deploymentTaskContext).failedWithError().build(); } finally { client.shutdown(); } return result; }