Problem in copying snapshot dependencies
Friends,
I am developing a tool to copy the existing projects.Currently the tool copies the projects but snapshot dependency properties were not copied as expected.
Problem is,
Source module’s property is “Do not run new build if there is a suitable one .Only use successful builds from suitable ones”
but copied module’s property is “Always run a new build” (which is a default value).
Tried to correct this issue by following code but unsuccessful.Please provide possible solutions.Thanks in advance for looking into my question.
String buildTypeId = buildTypeCopyFrom.getBuildTypeId(); //SBuildType to be copied
Dependency newDependencyToAdd = dependencyFactory.createDependency(buildTypeId);
//Dependency property #1
BooleanOption booleanOption = new BooleanOption("take-started-build-with-same-revisions",false);
newDependencyToAdd.getOption(booleanOption);
Boolean booleanValue = new Boolean(true);
newDependencyToAdd.setOption(booleanOption, booleanValue);
//Dependency property #2
BooleanOption booleanOption2 = new BooleanOption("take-successful-builds-only",false);
newDependencyToAdd.getOption(booleanOption2);
newDependencyToAdd.setOption(booleanOption2, booleanValue);
//Adding the dependency to the new project
if(buildTypeCopyFrom != null){
newProject.getBuildTypes().get(buildTypeSize).addDependency(newDependencyToAdd);
}Please sign in to leave a comment.
You should not create your own options, instead you should use options from DependencyOptions interface:
DependencyOptions.TAKE_STARTED_BUILD_WITH_SAME_REVISIONS
DependencyOptions.TAKE_SUCCESSFUL_BUILDS_ONLY
If your copy operation should behave like TeamCity copy, it is much easier to use: ProjectManager.createProject(SProject original, String newName, CopyOptions opts)
Note that when TeamCity copies projects it correctly maps dependencies to new configurations. For example, if you have project A with configuration A::Conf1 which has snapshot dependency on A::Conf2, the A project copy A' will have configuration A'::Conf1' snapshot dependent on A'::Conf2', instead of A::Conf2.
Another tricky part is VCS roots handling. VCS roots can be local (available to one project) and shared (available to all of the projects). The problem is - you can't attach local VCS root to another project, you have to either share it or create a copy of it in the new project. Not to mention that sometimes user notification rules and user roles should be handled too. The method I mentioned above takes care of these tricky problems.