Version Differences for Remoting Specific Scripts

(List Contents of a Build Life's Artifacts)
(AHPSCRIPTS-109)
Line 50:
       
  uow.close();</pre>    uow.close();</pre> 
       
    + = Update Environment Properties for All Projects =  
    + The idea here is that you may have secure value that is the same for all projects that are in a particular environment. Especially for passwords which could change regularly, going into each project to enter this is lame. Here's a remote script to do it.  
       
    + Something like:  
       
    + ah3client updateProjectEnvrionmentProperty.bsh user password Production password secret  
    + ==== AHPSCRIPTS-14 ====  
    + <pre>import com.urbancode.anthill3.main.client.AnthillClient;  
    + import com.urbancode.anthill3.persistence.UnitOfWork;  
    + import com.urbancode.anthill3.domain.project.*;  
    + import com.urbancode.anthill3.domain.project.envprops.*;  
    + import com.urbancode.anthill3.domain.servergroup.*;  
    + import java.util.*;  
       
    + String serverHost = "localhost";  
    + int serverPort = 4567;  
    + String userName = "admin";  
    + String password = "admin";  
       
    + String environmentName = "Password";  
    + String variableName = "my.var.name";  
    + String newVariableValue = "new value";  
       
       
    + //serverHost = bsh.args[0];  
    + //serverPort = Integer.parseInt(bsh.args[1]);  
       
    + if (bsh.args.length != 5) {  
    + print("");  
    + print("Invalid snyax. Please enter the command as: ");  
    + print("ah3client updateProjectEnvrionmentProperty.bsh [user name] [password] [environment name] [env property name] [new property value]");  
    + return 0;  
    + }  
       
    + userName = bsh.args[0];  
    + password = bsh.args[1];  
    + environmentName = bsh.args[2];  
    + variableName = bsh.args[3];  
    + newVariableValue = bsh.args[4];  
       
    + // obtain connection to the Anthill server  
    + AnthillClient anthill = AnthillClient.connect(serverHost, serverPort,  
    + userName, password);  
       
    + // create a Unit of Work  
    + UnitOfWork uow = anthill.createUnitOfWork();  
       
    + ServerGroup environment = ServerGroupFactory.getInstance().restoreForName(environmentName);  
    + if (environment == null) {  
    + print("Unknown environment: " + environmentName);  
    + throw new IllegalArgumentException("Unknown environment: " + environmentName);  
    + }  
       
       
       
    + // Project  
    + Project[] projects = ProjectFactory.getInstance().restoreAll();  
       
    + // Loop through projects. If it has environment props for this, find the  
    + // right one and change it as appropriate.  
    + for (int i = 0; i < projects.length; i++) {  
    + print("Inspecting: " + projects[i].getName());  
    +  
    + ProjectEnvironmentProperty[] envPropArray = environment.getEnvironmentPropertiesForProject(projects[i]);  
    + boolean foundVariable = false;  
    + for (int j = 0; j < envPropArray.length; j++) {  
    + if (envPropArray[j].getName().equals(variableName)) {  
    + foundVariable = true;  
    + envPropArray[j].setValue(newVariableValue);  
    + envPropArray[j].store();  
    + }  
    + }  
    +  
    + if (!foundVariable) {  
    + ProjectEnvironmentProperty newProp = new ProjectEnvironmentProperty(true);  
    +  
    + newProp.setProject(projects[i]);  
    + newProp.setServerGroup(environment);  
    + newProp.setName(variableName);  
    + newProp.setValue(newVariableValue);  
    + newProp.setSetAsEnvProp(false);  
    + newProp.setSecureValue(true);  
    +  
    + newProp.store();  
    + }  
    +  
    + }  
       
    + print("Committing Changes");  
    + uow.commitAndClose(); </pre>