Distributed Task#

Prerequisites#

See QuickStart

Examples#

Now that we have the connection object webApi, we can get the instance of DistributedTaskApi.

var task = webApi.getDistributedTaskApi();

We have access to the functionalities that Distributed Task Api has.

Available functions#

Delete an agent#

Delete a task agent by pool id and agent id.

Tip

You can get the agent Id and pool Id from the URL when you navigate to the agent pools section under organization Settings. Go to Organization settings --> Pipelines --> Agent Pools --> Select any agent. For the agent pool Azure Pipelines which is used for default tasks, if you click on agents tab you can get the pool Id and agent Id from the URL https://dev.azure.com/organization-name/project-name/_settings/agentpools?agentId=8&poolId=9&view=jobs

task.deleteAgent(9, 8);

Get an agent#

Get a task agent by pool id and agent id.

task.getAgent(9, 8);

Get all agents#

Get a list of all available agents with pool id.

task.getAgents(9);

Update an agent#

Update a task agent. You can get the parameters for request body from the API documentation.

task.updateAgent(9, 8, requestBody);

Add a deployment group#

Add a deployment group with name and description.

task.addDeploymentGroup("myDeploymentGroup", "This is a test deployment group");

/// Optionally create a deployment group and add a deployment pool to it
task.addDeploymentGroup("myDeploymentGroup", "This is a test deployment group", 9);

Delete a deployment group#

Delete a deployment group by id.

task.deleteDeploymentGroup("deploymentGroupId");

Get a deployment group#

Get a deployment group by id.

task.getDeploymentGroup("deploymentGroupId");

Get all deployment groups#

Get a list of deployment groups.

task.getDeploymentGroups();

Update a deployment group#

Update a deployment group's name and description by passing it's id.

task.updateDeploymentGroup("deploymentGroupId", "myNewDeploymentGroup", "This is my new deployment group");

Add an environment#

Add an environment by passing name and description.

task.addEnvironment("myEnvironment", "Description for my environment");

Delete an environment#

Delete an environment by id.

task.deleteEnvironment("environmentId");

Get an environment#

Get an environment by id.

task.getEnvironment("environmentId");

Get all environments#

Get a list of environments.

task.getEnvironments();

Update an environment#

Update an environment's name or description.

task.updateEnvironment("environmentId", "myNewEnvironment", "Description for my new environment");

Add a variable group#

Add a variable group.

var definition = new VariableGroupDefinition();
var projectReference = new ProjectReference();
var core = webApi.CoreApi();
var project = core.getProject("myProject");

var variables = new VariableGroupMap(){{
    put("userName", "testUser");
    put("passCode", "2255");
    put("details", "Test Value", VariableValue.IS_SECRET);
}};

projectReference.setName(project.getName());
projectReference.setId(project.getId());

definition.setName("myVariable");
definition.setDescription("Development variable group");
definition.setVariables(variables.get());
definition.setProjectReference(projectReference);
definition.setType(VariableGroupType.Vsts);

task.addVariableGroup(definition);

You can also use the helper method available to add the variable group.

task.addVariableGroup("myVariable", "Development variable group", variables);

Delete a variable group#

Delete a variable group by id.

task.deleteVariableGroup(12, new String[] { "projectId" });

Get a variable group#

Get a variable group by id.

task.getVariableGroup(11);

Get all variables groups#

Get a list of variable groups.

task.getVariableGroups();

Update a variable group#

Update a variable group by id.

Warning

You should pass all the existing variables along with the variable(s) that you want to update. Else the existing variables will be removed except the variable(s) that you're updating.

var variablesToUpdate = new HashMap<>(){{
    put("userName", new HashMap<>(){{
        put("value", "testUser");
    }});

    put("password", new HashMap<>(){{
        put("value", "testUser");
        put("isSecret", true);
    }});
}};

var group = d.getVariableGroups("myVariables")
    .getVariableGroups()
    .stream()
    .findFirst()
    .get();

task.updateVariableGroup(group.getId(), group.getName(), group.getDescription(), variablesToUpdate);