|
| 1 | +# Code snippets and samples |
| 2 | + |
| 3 | + |
| 4 | +## Operations |
| 5 | + |
| 6 | +- [List](#operations_list) |
| 7 | + |
| 8 | +## PipelineTemplateDefinitions |
| 9 | + |
| 10 | +- [List](#pipelinetemplatedefinitions_list) |
| 11 | + |
| 12 | +## Pipelines |
| 13 | + |
| 14 | +- [CreateOrUpdate](#pipelines_createorupdate) |
| 15 | +- [Delete](#pipelines_delete) |
| 16 | +- [GetByResourceGroup](#pipelines_getbyresourcegroup) |
| 17 | +- [List](#pipelines_list) |
| 18 | +- [ListByResourceGroup](#pipelines_listbyresourcegroup) |
| 19 | +- [Update](#pipelines_update) |
| 20 | +### Operations_List |
| 21 | + |
| 22 | +```java |
| 23 | +import com.azure.core.util.Context; |
| 24 | + |
| 25 | +/** Samples for Operations List. */ |
| 26 | +public final class OperationsListSamples { |
| 27 | + /* |
| 28 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/ListOperations.json |
| 29 | + */ |
| 30 | + /** |
| 31 | + * Sample code: Get a list of operations supported by Microsoft.DevOps resource provider. |
| 32 | + * |
| 33 | + * @param manager Entry point to DevopsManager. |
| 34 | + */ |
| 35 | + public static void getAListOfOperationsSupportedByMicrosoftDevOpsResourceProvider( |
| 36 | + com.azure.resourcemanager.devops.DevopsManager manager) { |
| 37 | + manager.operations().list(Context.NONE); |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +### PipelineTemplateDefinitions_List |
| 43 | + |
| 44 | +```java |
| 45 | +import com.azure.core.util.Context; |
| 46 | + |
| 47 | +/** Samples for PipelineTemplateDefinitions List. */ |
| 48 | +public final class PipelineTemplateDefinitionsListSamples { |
| 49 | + /* |
| 50 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/ListPipelineTemplateDefinitions.json |
| 51 | + */ |
| 52 | + /** |
| 53 | + * Sample code: Get the list of pipeline template definitions. |
| 54 | + * |
| 55 | + * @param manager Entry point to DevopsManager. |
| 56 | + */ |
| 57 | + public static void getTheListOfPipelineTemplateDefinitions(com.azure.resourcemanager.devops.DevopsManager manager) { |
| 58 | + manager.pipelineTemplateDefinitions().list(Context.NONE); |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### Pipelines_CreateOrUpdate |
| 64 | + |
| 65 | +```java |
| 66 | +import com.azure.resourcemanager.devops.models.BootstrapConfiguration; |
| 67 | +import com.azure.resourcemanager.devops.models.OrganizationReference; |
| 68 | +import com.azure.resourcemanager.devops.models.PipelineTemplate; |
| 69 | +import com.azure.resourcemanager.devops.models.ProjectReference; |
| 70 | +import java.util.HashMap; |
| 71 | +import java.util.Map; |
| 72 | + |
| 73 | +/** Samples for Pipelines CreateOrUpdate. */ |
| 74 | +public final class PipelinesCreateOrUpdateSamples { |
| 75 | + /* |
| 76 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/CreateAzurePipeline-Sample-AspNet-WindowsWebApp.json |
| 77 | + */ |
| 78 | + /** |
| 79 | + * Sample code: Create an Azure pipeline to deploy a sample ASP.Net application to Azure web-app. |
| 80 | + * |
| 81 | + * @param manager Entry point to DevopsManager. |
| 82 | + */ |
| 83 | + public static void createAnAzurePipelineToDeployASampleASPNetApplicationToAzureWebApp( |
| 84 | + com.azure.resourcemanager.devops.DevopsManager manager) { |
| 85 | + manager |
| 86 | + .pipelines() |
| 87 | + .define("myAspNetWebAppPipeline") |
| 88 | + .withRegion("South India") |
| 89 | + .withExistingResourceGroup("myAspNetWebAppPipeline-rg") |
| 90 | + .withOrganization(new OrganizationReference().withName("myAspNetWebAppPipeline-org")) |
| 91 | + .withProject(new ProjectReference().withName("myAspNetWebAppPipeline-project")) |
| 92 | + .withBootstrapConfiguration( |
| 93 | + new BootstrapConfiguration() |
| 94 | + .withTemplate( |
| 95 | + new PipelineTemplate() |
| 96 | + .withId("ms.vss-continuous-delivery-pipeline-templates.aspnet-windowswebapp") |
| 97 | + .withParameters( |
| 98 | + mapOf( |
| 99 | + "appInsightLocation", |
| 100 | + "South India", |
| 101 | + "appServicePlan", |
| 102 | + "S1 Standard", |
| 103 | + "azureAuth", |
| 104 | + "{\"scheme\":\"ServicePrincipal\",\"parameters\":{\"tenantid\":\"{subscriptionTenantId}\",\"objectid\":\"{appObjectId}\",\"serviceprincipalid\":\"{appId}\",\"serviceprincipalkey\":\"{appSecret}\"}}", |
| 105 | + "location", |
| 106 | + "South India", |
| 107 | + "resourceGroup", |
| 108 | + "myAspNetWebAppPipeline-rg", |
| 109 | + "subscriptionId", |
| 110 | + "{subscriptionId}", |
| 111 | + "webAppName", |
| 112 | + "myAspNetWebApp")))) |
| 113 | + .withTags(mapOf()) |
| 114 | + .create(); |
| 115 | + } |
| 116 | + |
| 117 | + @SuppressWarnings("unchecked") |
| 118 | + private static <T> Map<String, T> mapOf(Object... inputs) { |
| 119 | + Map<String, T> map = new HashMap<>(); |
| 120 | + for (int i = 0; i < inputs.length; i += 2) { |
| 121 | + String key = (String) inputs[i]; |
| 122 | + T value = (T) inputs[i + 1]; |
| 123 | + map.put(key, value); |
| 124 | + } |
| 125 | + return map; |
| 126 | + } |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +### Pipelines_Delete |
| 131 | + |
| 132 | +```java |
| 133 | +import com.azure.core.util.Context; |
| 134 | + |
| 135 | +/** Samples for Pipelines Delete. */ |
| 136 | +public final class PipelinesDeleteSamples { |
| 137 | + /* |
| 138 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/DeleteAzurePipeline.json |
| 139 | + */ |
| 140 | + /** |
| 141 | + * Sample code: Get an existing Azure pipeline. |
| 142 | + * |
| 143 | + * @param manager Entry point to DevopsManager. |
| 144 | + */ |
| 145 | + public static void getAnExistingAzurePipeline(com.azure.resourcemanager.devops.DevopsManager manager) { |
| 146 | + manager.pipelines().deleteWithResponse("myAspNetWebAppPipeline-rg", "myAspNetWebAppPipeline", Context.NONE); |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +### Pipelines_GetByResourceGroup |
| 152 | + |
| 153 | +```java |
| 154 | +import com.azure.core.util.Context; |
| 155 | + |
| 156 | +/** Samples for Pipelines GetByResourceGroup. */ |
| 157 | +public final class PipelinesGetByResourceGroupSamples { |
| 158 | + /* |
| 159 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/GetAzurePipeline.json |
| 160 | + */ |
| 161 | + /** |
| 162 | + * Sample code: Get an existing Azure pipeline. |
| 163 | + * |
| 164 | + * @param manager Entry point to DevopsManager. |
| 165 | + */ |
| 166 | + public static void getAnExistingAzurePipeline(com.azure.resourcemanager.devops.DevopsManager manager) { |
| 167 | + manager |
| 168 | + .pipelines() |
| 169 | + .getByResourceGroupWithResponse("myAspNetWebAppPipeline-rg", "myAspNetWebAppPipeline", Context.NONE); |
| 170 | + } |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +### Pipelines_List |
| 175 | + |
| 176 | +```java |
| 177 | +import com.azure.core.util.Context; |
| 178 | + |
| 179 | +/** Samples for Pipelines List. */ |
| 180 | +public final class PipelinesListSamples { |
| 181 | + /* |
| 182 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/ListAzurePipelinesBySubscription.json |
| 183 | + */ |
| 184 | + /** |
| 185 | + * Sample code: List all Azure pipelines under the specified subscription. |
| 186 | + * |
| 187 | + * @param manager Entry point to DevopsManager. |
| 188 | + */ |
| 189 | + public static void listAllAzurePipelinesUnderTheSpecifiedSubscription( |
| 190 | + com.azure.resourcemanager.devops.DevopsManager manager) { |
| 191 | + manager.pipelines().list(Context.NONE); |
| 192 | + } |
| 193 | +} |
| 194 | +``` |
| 195 | + |
| 196 | +### Pipelines_ListByResourceGroup |
| 197 | + |
| 198 | +```java |
| 199 | +import com.azure.core.util.Context; |
| 200 | + |
| 201 | +/** Samples for Pipelines ListByResourceGroup. */ |
| 202 | +public final class PipelinesListByResourceGroupSamples { |
| 203 | + /* |
| 204 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/ListAzurePipelinesByResourceGroup.json |
| 205 | + */ |
| 206 | + /** |
| 207 | + * Sample code: List all Azure Pipelines under the specified resource group. |
| 208 | + * |
| 209 | + * @param manager Entry point to DevopsManager. |
| 210 | + */ |
| 211 | + public static void listAllAzurePipelinesUnderTheSpecifiedResourceGroup( |
| 212 | + com.azure.resourcemanager.devops.DevopsManager manager) { |
| 213 | + manager.pipelines().listByResourceGroup("myAspNetWebAppPipeline-rg", Context.NONE); |
| 214 | + } |
| 215 | +} |
| 216 | +``` |
| 217 | + |
| 218 | +### Pipelines_Update |
| 219 | + |
| 220 | +```java |
| 221 | +import com.azure.core.util.Context; |
| 222 | +import com.azure.resourcemanager.devops.models.Pipeline; |
| 223 | +import java.util.HashMap; |
| 224 | +import java.util.Map; |
| 225 | + |
| 226 | +/** Samples for Pipelines Update. */ |
| 227 | +public final class PipelinesUpdateSamples { |
| 228 | + /* |
| 229 | + * x-ms-original-file: specification/devops/resource-manager/Microsoft.DevOps/preview/2019-07-01-preview/examples/UpdateAzurePipeline.json |
| 230 | + */ |
| 231 | + /** |
| 232 | + * Sample code: Get an existing Azure pipeline. |
| 233 | + * |
| 234 | + * @param manager Entry point to DevopsManager. |
| 235 | + */ |
| 236 | + public static void getAnExistingAzurePipeline(com.azure.resourcemanager.devops.DevopsManager manager) { |
| 237 | + Pipeline resource = |
| 238 | + manager |
| 239 | + .pipelines() |
| 240 | + .getByResourceGroupWithResponse("myAspNetWebAppPipeline-rg", "myAspNetWebAppPipeline", Context.NONE) |
| 241 | + .getValue(); |
| 242 | + resource.update().withTags(mapOf("tagKey", "tagvalue")).apply(); |
| 243 | + } |
| 244 | + |
| 245 | + @SuppressWarnings("unchecked") |
| 246 | + private static <T> Map<String, T> mapOf(Object... inputs) { |
| 247 | + Map<String, T> map = new HashMap<>(); |
| 248 | + for (int i = 0; i < inputs.length; i += 2) { |
| 249 | + String key = (String) inputs[i]; |
| 250 | + T value = (T) inputs[i + 1]; |
| 251 | + map.put(key, value); |
| 252 | + } |
| 253 | + return map; |
| 254 | + } |
| 255 | +} |
| 256 | +``` |
| 257 | + |
0 commit comments