Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created February 13, 2016 00:27
Show Gist options
  • Save guitarrapc/f1d0c936a7ff7eab5673 to your computer and use it in GitHub Desktop.
Save guitarrapc/f1d0c936a7ff7eab5673 to your computer and use it in GitHub Desktop.
async Task Main()
{
var apiKey = "Input your Api Key";
var orgId = "Input Target OrgId";
var projectId = "Input ProjectId";
var client = new UnityCloudBuildApi.IO.Swagger.Client.ApiClient("https://build-api.cloud.unity3d.com/api/v1");
var config = new UnityCloudBuildApi.IO.Swagger.Client.Configuration(client, accessToken: apiKey);
#region Project Api
// Get Project
var projectApi = new UnityCloudBuildApi.IO.Swagger.Api.ProjectsApi(config);
var proejct = await projectApi.GetBillingPlansAsync(orgId, projectId);
proejct.Dump();
// List Project
var listProject = await projectApi.ListProjectsForOrgAsync(orgId);
listProject.Dump();
// Add Project
var options = new UnityCloudBuildApi.IO.Swagger.Model.Options
{
Name = "Test",
Settings = new UnityCloudBuildApi.IO.Swagger.Model.OrgsorgidprojectsSettings
{
Scm = new UnityCloudBuildApi.IO.Swagger.Model.OrgsorgidprojectsSettingsScm
{
Url = "https://github.com/username/repositoryname.git",
Type = "git",
User = "github user name",
Pass = "github api token",
},
},
};
var addProject = await projectApi.AddProjectAsync(orgId, options);
addProject.Dump();
#endregion
#region BuildTarget Api
// Add Build Target
var buildTargetApi = new UnityCloudBuildApi.IO.Swagger.Api.BuildtargetsApi(config);
var option2 = new UnityCloudBuildApi.IO.Swagger.Model.Options2
{
Platform = "android",
Name = "Test",
Enabled = false,
Settings = new UnityCloudBuildApi.IO.Swagger.Model.OrgsorgidprojectsprojectidbuildtargetsSettings
{
Platform = new UnityCloudBuildApi.IO.Swagger.Model.OrgsorgidprojectsprojectidbuildtargetsSettingsPlatform {BundleId = "com.hoge.fuga"},
AutoBuild = true,
Scm = new UnityCloudBuildApi.IO.Swagger.Model.OrgsorgidprojectsprojectidbuildtargetsSettingsScm
{
Branch = "master",
Type = "git"
},
UnityVersion = "latest",
},
};
var newBuildTarget = await buildTargetApi.AddBuildTargetAsync(orgId, projectId, option2);
newBuildTarget.Dump();
// Get BuildTargets for list BuildTargetId
var buildTargets = await buildTargetApi.GetBuildTargetsAsync(orgId, projectId);
// Get BuildTarget Info
var buildTarget = await buildTargetApi.GetBuildTargetAsync(orgId, projectId, buildTargets.FirstOrDefault().Buildtargetid);
#endregion
#region Build Api
// Get Build Detail
var buildApi = new UnityCloudBuildApi.IO.Swagger.Api.BuildsApi(config);
var build = await buildApi.GetBuildsAsync(orgId, projectId, buildTargets.FirstOrDefault().Buildtargetid);
// Start Build
var option = new UnityCloudBuildApi.IO.Swagger.Model.Options4
{
Clean = false,
Delay = 0,
};
var startBuild = await buildApi.StartBuildsAsync(orgId, projectId, buildTargets.FirstOrDefault().Buildtargetid, option);
startBuild.Dump();
// Cancel All Build
foreach (var item in build.Where(x => x.BuildStatus == "queued"))
{
//var cancelBuilds = await buildApi.CancelAllBuildsAsync(orgId, projectId, item.Buildtargetid);
//cancelBuilds.Dump();
}
// Cancel Specific Builds
var cancelBuild = await buildApi.CancelBuildAsync(orgId, projectId, buildTargets.FirstOrDefault().Buildtargetid, startBuild.FirstOrDefault().Build.ToString());
cancelBuild.Dump();
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment