With Anthill Pro how can I programmatically kick off a new build?

2k Views Asked by At

I want to programatically kick off an Anthill job from another system and set some build properties (the Git branch).

What API exists to help me do that?

2

There are 2 best solutions below

0
On

You'll need to the Anthill SDK (click the 'tools' link at the top of the Anthill Pro screen)

Add the remoting/lib and remoting/conf to you classpath. Using these imports:

import com.urbancode.anthill3.domain.buildrequest.BuildRequest;
import com.urbancode.anthill3.domain.buildrequest.RequestSourceEnum;
import com.urbancode.anthill3.domain.project.Project;
import com.urbancode.anthill3.domain.project.ProjectFactory;
import com.urbancode.anthill3.domain.security.User;
import com.urbancode.anthill3.domain.security.UserFactory;
import com.urbancode.anthill3.domain.trigger.remoterequest.repository.RepositoryRequestTrigger;
import com.urbancode.anthill3.domain.workflow.Workflow;
import com.urbancode.anthill3.main.client.AnthillClient;
import com.urbancode.anthill3.persistence.UnitOfWork;
import com.urbancode.anthill3.runtime.scripting.helpers.WorkflowLookup;
import com.urbancode.anthill3.services.build.BuildService;

This code will look up a project and workflow then kick off a build.

    AnthillClient anthill = AnthillClient.connect(hostStage, remotingPort, username, password);
    UnitOfWork uow = anthill.createUnitOfWork();

    Project prj = ProjectFactory.getInstance().restoreForName("My Project");  //'My Project' is the project name.
    Workflow wflow = WorkflowLookup.getForProjectAndName(prj, "My Workflow"); //'My Workflow' is the workflows name/key

    User usr = UserFactory.getInstance().restoreForName("username");

    RepositoryRequestTrigger req1 = new RepositoryRequestTrigger();
    req1.setWorkflow(wflow);
    req1.setNew();
    req1.setName("Git Repository Trigger");

    uow.register(req1);
    uow.commit();

    BuildRequest br = BuildRequest.createOriginatingRequest(wflow.getBuildProfile(),usr, RequestSourceEnum.EVENT,req1);
    br.setForcedFlag(true);

    //Set any build properties here
    br.setPropertyValue("gitBranch","develop",false);
    BuildService.getInstance().runBuild(br);
1
On

An alternative (simpler but less flexible) approach... Create a Trigger on the build workflow and use wget or curl to send an HTTP POST to Anthill passing the required parameters with the POST.

Here is a way to send an HTTP POST using an HTML FORM.

http://anthillizer.com/display/main/How+to+create+a+simple+tool+to+fire+an+AnthillPro+CI+Trigger You can do the same thing with wget.

Hope this helps! Eric