Workflow Properties

This page lists scripts to make scripted workflow properties. These scripts were taken straight from the public JIRA site. Please note that some scripts may be snippets and probably WILL need modification to work properly for your situation. Treat these as templates that you can modify from.

Select the Agent in Environment to Run on

  • Give the user the ability to select which agent the workflow should run on using a dynmic workflow property and a agent filter.

AHPSCRIPTS-112

  • Create a new Agent Filter script that will return all agents that are referenced in a property value. The property name I use is 'agents' which you can change. It should be the name of the workflow property you will add that allows them to be selected. Here is the script:
import com.urbancode.anthill3.domain.agent.Agent; 
 import java.util.*; 

 return new Where() { 
    public Agent[] filter(Agent[] agents) { 
        agentNames = PropertyLookup.get("agents"); 
        nameArray = agentNames.split(","); 
        agentList = new ArrayList(); 
        for (int a=0; a<agents.length; a++) { 
            for (int n=0; n<nameArray.length; n++) { 
                if (agents[a].getName().equals(nameArray[n])) { 
                    agentList.add(agents[a]); 
                } 
            } 
        } 
        agents = agentList.toArray(new Agent[agentList.size()]); 
        return agents; 
    } 
 };
  • On your workflow, create a multi-select property that is scripted. In my example, I name it 'agents' and the Agent Filter script needs to use the same name. It should be user overrideable and required. The script for value I used is:
import com.urbancode.anthill3.services.agent.AgentManager; 
 import com.urbancode.anthill3.domain.agent.AgentFactory; 

 endpoints = AgentManager.getInstance().getOnLineEndpointArray(environment); 
 values = new String[endpoints.length]; 
 for (int i=0; i<endpoints.length; i++) { 
    agent = AgentFactory.getInstance().restoreByEndpoint(endpoints[i]); 
    values[i] = agent.getName(); 
 } 
 return values;

Get Value From Database

AHPSCRIPTS-113

    import java.sql.*; 
     import java.util.*; 
      
     String url = "jdbc:sqlserver://SomeDatabaseServer:1433;DatabaseName=SomeDatabase"; 
   
     List valueList = new ArrayList(); 
      
     try { 
       Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
     } 
     catch (Exception e) { 
       throw new Exception("Failed to load SQL Server driver."); 
     } 
     try { 
       Connection conn = DriverManager.getConnection(url, "username", "password"); 
       Statement statement = conn.createStatement(); 
       ResultSet rs = select.executeQuery("SELECT value FROM my_table"); 
   
       while (rs.next()) { 
         String value = rs.getString("value"); 
         valueList.add(value); 
       } 
        
       rs.close(); 
       statement.close(); 
       con.close(); 
     } 
     catch (Exception e) { 
       throw new Exception("Error querying database for values", e); 
     } 
      
     return valueList.toArray(new String[valueList.size()]);