|
(→AHPSCRIPTS-102)
|
(→Based on Property That Contains Value of Agent Property)
|
| Line 399: | |||
| <pre>String propValue = PropertyLookup.get("property"); | <pre>String propValue = PropertyLookup.get("property"); | ||
| return Where.is(Variable.equals("property", propValue));</pre> | return Where.is(Variable.equals("property", propValue));</pre> | ||
| + | = Filter Agents by Hostname Using Property Containing the Name = | ||
| + | ==== AHPSCRIPTS-124 ==== | ||
| + | <pre>// Define a property "host" in the project, workflow or job iteration. | ||
| + | import com.urbancode.anthill3.domain.agent.Agent; | ||
| + | import com.urbancode.anthill3.runtime.scripting.helpers.*; | ||
| + | return new Where() { | ||
| + | public Agent[] filter(Agent[] agents) { | ||
| + | // assumes that the build job was the first job in orig-workflow | ||
| + | String host = PropertyLookup.get("host"); | ||
| + | List agentList = new ArrayList(); | ||
| + | for (Agent agent : agents) { | ||
| + | if (agent.getHostname().equalsIgnoreCase(host)) { | ||
| + | agentList.add(agent); | ||
| + | } | ||
| + | } | ||
| + | return (Agent[]) agentList.toArray(new Agent[agentList.size()]); | ||
| + | } | ||
| + | };</pre> | ||