use of de.tum.in.www1.artemis.exception.BambooException in project ArTEMiS by ls1intum.
the class BambooService method deletePlan.
/**
* Deletes the given plan.
*
* @param projectKey
* @param planKey
* @return
*/
public String deletePlan(String projectKey, String planKey) {
try {
log.info("Delete build plan " + projectKey + "-" + planKey);
String message = getBambooClient().getPlanHelper().deletePlan(projectKey + "-" + planKey);
log.info("Delete build plan was successful. " + message);
return message;
} catch (CliClient.ClientException | CliClient.RemoteRestException e) {
log.error(e.getMessage(), e);
throw new BambooException("Something went wrong while deleting the build plan", e);
}
}
use of de.tum.in.www1.artemis.exception.BambooException in project ArTEMiS by ls1intum.
the class BambooService method updatePlanRepository.
/**
* Updates the configured repository for a given plan to the given Bitbucket Server repository.
*
* @param bambooProject The key of the Bamboo plan's project, e.g. 'EIST16W1'.
* @param bambooPlan The plan key, which is usually the name, e.g. 'ga56hur'.
* @param bambooRepositoryName The name of the configured repository in the Bamboo plan.
* @param bitbucketProject The key for the Bitbucket Server (formerly Stash) project to which we want to update the plan.
* @param bitbucketRepository The name/slug for the Bitbucket Server (formerly Stash) repository to which we want to update the plan.
*/
public String updatePlanRepository(String bambooProject, String bambooPlan, String bambooRepositoryName, String bitbucketProject, String bitbucketRepository) throws BambooException {
final BambooClient bambooClient = new BambooClient();
String[] args = new String[] { "--field1", "repository.stash.projectKey", "--value1", bitbucketProject, // Doesn't seem to be required
"--field2", // Doesn't seem to be required
"repository.stash.repositoryId", // Doesn't seem to be required
"--value2", // Doesn't seem to be required
"2499", "--field3", "repository.stash.repositorySlug", "--value3", bitbucketRepository, // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
"--field4", // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
"repository.stash.repositoryUrl", // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
"--value4", // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
buildSshRepositoryUrl(bitbucketProject, bitbucketRepository), "--field5", "repository.stash.server", "--value5", BITBUCKET_APPLICATION_LINK_ID, "--field6", "repository.stash.branch", "--value6", "master", "-s", BAMBOO_SERVER_URL.toString(), "--user", BAMBOO_USER, "--password", BAMBOO_PASSWORD };
// workaround to pass additional fields
bambooClient.doWork(args);
try {
log.info("Update plan repository for build plan " + bambooProject + "-" + bambooPlan);
String message = bambooClient.getRepositoryHelper().addOrUpdateRepository(bambooRepositoryName, null, null, bambooProject + "-" + bambooPlan, "STASH", null, false, true, true);
log.info("Update plan repository for build plan " + bambooProject + "-" + bambooPlan + " was successful." + message);
return message;
} catch (CliClient.ClientException | CliClient.RemoteRestException e) {
log.error(e.getMessage(), e);
throw new BambooException("Something went wrong while updating the plan repository", e);
}
}
use of de.tum.in.www1.artemis.exception.BambooException in project ArTEMiS by ls1intum.
the class BambooService method clonePlan.
/**
* Clones an existing Bamboo plan.
*
* @param baseProject The Bamboo project in which the plan is contained.
* @param basePlan The plan's name.
* @param name The name to give the cloned plan.
* @return The name of the new build plan
*/
public String clonePlan(String baseProject, String basePlan, String name) throws BambooException {
String toPlan = baseProject + "-" + name;
try {
log.info("Clone build plan " + baseProject + "-" + basePlan + " to " + toPlan);
String message = getBambooClient().getPlanHelper().clonePlan(baseProject + "-" + basePlan, toPlan, toPlan, "", "", true);
log.info("Clone build plan " + toPlan + " was successful." + message);
} catch (CliClient.ClientException clientException) {
log.error(clientException.getMessage(), clientException);
if (clientException.getMessage().contains("already exists")) {
throw new BambooException(clientException.getMessage());
}
} catch (CliClient.RemoteRestException e) {
log.error(e.getMessage(), e);
throw new BambooException("Something went wrong while cloning build plan", e);
}
return toPlan;
}
use of de.tum.in.www1.artemis.exception.BambooException in project ArTEMiS by ls1intum.
the class ExerciseService method cleanup.
/**
* Delete build plans (except BASE) and optionally repositores of all exercise participations.
*
* @param id id of the exercise for which build plans in respective participations are deleted
*/
@Transactional
public java.io.File cleanup(Long id, boolean deleteRepositories) throws java.io.IOException {
Exercise exercise = findOneLoadParticipations(id);
log.info("Request to cleanup all participations for Exercise : {}", exercise.getTitle());
List<Repository> studentRepositories = new ArrayList<>();
Path finalZipFilePath = null;
if (Optional.ofNullable(exercise).isPresent() && exercise instanceof ProgrammingExercise) {
exercise.getParticipations().forEach(participation -> {
if (participation.getBuildPlanId() != null) {
// ignore participations without build plan id
try {
continuousIntegrationService.get().deleteBuildPlan(participation.getBuildPlanId());
} catch (BambooException ex) {
log.error(ex.getMessage());
if (ex.getCause() != null) {
log.error(ex.getCause().getMessage());
}
}
participation.setInitializationState(ParticipationState.INACTIVE);
participation.setBuildPlanId(null);
participationService.save(participation);
}
if (deleteRepositories == true && participation.getRepositoryUrl() != null) {
// ignore participations without repository URL
try {
// 1. clone the repository
Repository repo = gitService.get().getOrCheckoutRepository(participation);
// 2. collect the repo file
studentRepositories.add(repo);
} catch (GitAPIException | IOException ex) {
log.error("Archiving and deleting the repository " + participation.getRepositoryUrlAsUrl() + " did not work as expected", ex);
}
}
});
if (deleteRepositories == false) {
// in this case, we are done
return null;
}
if (studentRepositories.isEmpty()) {
log.info("No student repositories have been found.");
return null;
}
// from here on, deleteRepositories is true and does not need to be evaluated again
log.info("Create zip file for all repositories");
Files.createDirectories(Paths.get("zippedRepos"));
finalZipFilePath = Paths.get("zippedRepos", exercise.getCourse().getTitle() + " " + exercise.getTitle() + " Student Repositories.zip");
zipAllRepositories(studentRepositories, finalZipFilePath);
exercise.getParticipations().forEach(participation -> {
if (participation.getRepositoryUrl() != null) {
// ignore participations without repository URL
try {
// 3. delete the locally cloned repo again
gitService.get().deleteLocalRepository(participation);
} catch (IOException e) {
log.error("Archiving and deleting the repository " + participation.getRepositoryUrlAsUrl() + " did not work as expected", e);
}
// 4. finally delete the repository on the VC Server
versionControlService.get().deleteRepository(participation.getRepositoryUrlAsUrl());
participation.setRepositoryUrl(null);
participation.setInitializationState(ParticipationState.FINISHED);
participationService.save(participation);
}
});
scheduleForDeletion(finalZipFilePath, 300);
} else {
log.info("Exercise with id {} is not an instance of ProgrammingExercise. Ignoring the request to cleanup repositories and build plan", id);
return null;
}
return new java.io.File(finalZipFilePath.toString());
}
use of de.tum.in.www1.artemis.exception.BambooException in project ArTEMiS by ls1intum.
the class BambooService method enablePlan.
/**
* Enables the given build plan.
*
* @param projectKey
* @param planKey
* @return
*/
public String enablePlan(String projectKey, String planKey) throws BambooException {
try {
log.info("Enable build plan " + projectKey + "-" + planKey);
String message = getBambooClient().getPlanHelper().enablePlan(projectKey + "-" + planKey, true);
log.info("Enable build plan " + projectKey + "-" + planKey + " was successful. " + message);
return message;
} catch (CliClient.ClientException | CliClient.RemoteRestException e) {
log.error(e.getMessage(), e);
throw new BambooException("Something went wrong while enabling the build plan", e);
}
}
Aggregations