Beispiel #1
0
        public WebApiRelease AbandonAnActiveRelease()
        {
            string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;

            // Get a release client instance
            VssConnection     connection    = Context.Connection;
            ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>();

            WebApiRelease release = CreateRelease(releaseClient, newlyCreatedReleaseDefinitionId, projectName);

            ReleaseUpdateMetadata releaseUpdateMetadata = new ReleaseUpdateMetadata()
            {
                Comment = "Abandon the release",
                Status  = ReleaseStatus.Abandoned
            };

            // Abandon a release
            WebApiRelease updatedRelease = releaseClient.UpdateReleaseResourceAsync(releaseUpdateMetadata, projectName, release.Id).Result;

            Console.WriteLine("{0} {1}", updatedRelease.Id.ToString().PadLeft(6), updatedRelease.Name);

            return(release);
        }
Beispiel #2
0
        public static async Task <HttpResponseMessage> TestableRun(HttpRequestMessage req, TraceWriter log,
                                                                   ReleaseHttpClientTestableWrapper releaseHttpClientTestableWrapper,
                                                                   ReleaseHttpClient rmClient)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // Get request body & variables
            dynamic content = await req.Content.ReadAsAsync <object>();

            //dynamic content = JsonConvert.DeserializeObject(requestBody);
            string projectId     = content.id;
            string dynDomain     = content.instance;
            string username      = content.username;
            string password      = content.password;
            string deployerEmail = content.email;
            bool   resetInstance = content.resetInstance;

            var split     = username.Split('@');
            var dynUser   = split[0];
            var dynTenant = split[1];

            var releaseDefinitions = releaseHttpClientTestableWrapper.GetReleaseDefinitions(projectId, rmClient);

            var releaseDefinition = releaseDefinitions.First();

            var primaryArtifact   = releaseDefinition.Artifacts.SingleOrDefault(a => a.IsPrimary);
            var projectName       = primaryArtifact.DefinitionReference["project"].Id;
            var buildDefinitionId = Convert.ToInt32(primaryArtifact.DefinitionReference["definition"].Id);

            // Create the draft release, and use the build defined in the current primary artificat
            var metadata = new ReleaseStartMetadata
            {
                DefinitionId = releaseDefinition.Id,
                IsDraft      = true,
                Description  = $"https://{dynDomain}.crm.dynamics.com ({username}), initiated by {deployerEmail} from Azure Function.",
                Artifacts    = new[]
                {
                    new ArtifactMetadata
                    {
                        Alias             = primaryArtifact.Alias,
                        InstanceReference = new BuildVersion
                        {
                            Id   = primaryArtifact.DefinitionReference["defaultVersionSpecific"].Id,
                            Name = primaryArtifact.DefinitionReference["defaultVersionSpecific"].Name
                        }
                    }
                }
            };
            var release = releaseHttpClientTestableWrapper.CreateRelease(metadata, projectId, rmClient);

            // Update the draft release variable
            var environment = release.Environments[0];

            environment.Variables["dynDomain"].Value   = dynDomain;
            environment.Variables["dynUser"].Value     = dynUser;
            environment.Variables["dynPassword"].Value = password;
            environment.Variables["dynTenant"].Value   = dynTenant;
            environment.Variables["emailNotificationAddress"].Value = deployerEmail;
            environment.Variables["resetInstance"].Value            = resetInstance.ToString();

            if (projectId == "1ba2fb0e-cca7-46c3-b926-7828f224a406") // Azure Service Bus and Functions
            {
                var azUniqueName = Regex.Replace(dynDomain, "[^a-zA-Z0-9]", "");
                environment.Variables["azUniqueName"].Value    = azUniqueName;
                environment.Variables["azResourceGroup"].Value = $"dd-{azUniqueName}-rg";
            }

            release = releaseHttpClientTestableWrapper.UpdateRelease(release, projectId, release.Id, rmClient);

            // Activate the release
            var updateMetadata = new ReleaseUpdateMetadata {
                Status = ReleaseStatus.Active, Comment = "Automated by Demo Deployer"
            };

            release = releaseHttpClientTestableWrapper.UpdateReleaseResource(updateMetadata, projectId, release.Id, rmClient);

            // Issue in PowerApps, which I couldn't get around, is why I'm not sending 200 for success and 400 for errors.
            // https://community.powerapps.com/t5/General-Discussion/Error-handling-with-Custom-API/td-p/7719
            // https://powerusers.microsoft.com/t5/General-Discussion/Extracting-Error-Message-From-PowerApps-Control-and-Store-in/td-p/79494
            dynamic response = new JObject();

            response.status = "success";

            return(req.CreateResponse(HttpStatusCode.OK, (JObject)response, Settings.JsonFormatter));
        }
Beispiel #3
0
 public virtual Release UpdateReleaseResource(ReleaseUpdateMetadata updateMetadata, string projectId, int releaseId, ReleaseHttpClient rmClient)
 {
     return(rmClient.UpdateReleaseResourceAsync(updateMetadata, projectId, releaseId).Result);
 }