コード例 #1
0
        public static DevOpsBuild QueueBuild([ActivityTrigger] DevOpsBuildContext buildContext, ILogger log)
        {
            log.LogInformation($"Kicking off a build for {buildContext.BuildTaskName}...");
            string      authToken = EnvironmentHelper.GetAuthToken();
            DevOpsBuild build     = DevOpsHelper.QueueDevOpsBuild(buildContext, authToken, log).Result;

            return(build);
        }
コード例 #2
0
        public static async Task <DevOpsBuild> OrchestrateBuild([OrchestrationTrigger] DurableOrchestrationContext context)
        {
            DevOpsBuildContext buildContext = context.GetInput <DevOpsBuildContext>();
            DevOpsBuild        build        = await context.CallActivityAsync <DevOpsBuild>("BuildManager_QueueBuild", buildContext);

            DateTime expiry          = context.CurrentUtcDateTime + TimeSpan.FromMinutes(Constants.PollSettings.expiryMinutes);
            TimeSpan pollingInterval = TimeSpan.FromSeconds(Constants.PollSettings.pollingIntervalSecs);

            while (context.CurrentUtcDateTime < expiry)
            {
                build = await context.CallActivityAsync <DevOpsBuild>("BuildManager_GetBuildStatus", build.Url);

                if (build.Status == BuildStatus.completed)
                {
                    // For worker builds we need to get the artifacts and upload it
                    if (Constants.LanguageWorkersForBuild.Contains(buildContext.Agent) &&
                        EnvironmentHelper.ShouldUploadArtifact())
                    {
                        var artifactContext = ContextProvider.GetWorkerArtifactContext(build.Id, buildContext.Agent);
                        var artifact        = await context.CallActivityAsync <DevOpsArtifact>("BuildManager_GetBuildArtifact", artifactContext);

                        if (artifact != null)
                        {
                            // TODO: change the platform here
                            var uploadContext = ContextProvider.GetWorkerArtifactUploadContext(artifact,
                                                                                               $"{Utilities.BuildTypeToCon(buildContext.BuildType)}", buildContext.Agent);

                            await context.CallActivityAsync("BuildManager_UploadToStorage", uploadContext);
                        }
                        // TODO: if it is null, a special failed tests file should be dropped at the storage account
                    }
                    return(build);
                }

                // Orchestration sleeps until this time.
                var nextCheck = context.CurrentUtcDateTime + pollingInterval;
                await context.CreateTimer(nextCheck, CancellationToken.None);
            }

            // TODO: Need to verify that this is ok
            // and probably throw a "failure" log
            return(build);
        }
コード例 #3
0
        public static async Task <DevOpsBuild> QueueDevOpsBuild(DevOpsBuildContext buildContext, string authToken, ILogger logger)
        {
            Uri         url         = new Uri(Endpoints.GetQueueBuildUrl(buildContext.Organization, buildContext.Project));
            DevOpsBuild devOpsBuild = new DevOpsBuild
            {
                Definition = new Definition
                {
                    Id = buildContext.DefinitionId
                }
            };

            if (buildContext.Parameters.Count != 0)
            {
                devOpsBuild.Parameters = JsonConvert.SerializeObject(buildContext.Parameters);
            }
            var bearerToken = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", authToken)));

            var response = await DevOpsClient.HttpInvoke("POST", url, bearerToken, devOpsBuild, logger);

            response.EnsureSuccessStatusCode();
            var responseContent = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <DevOpsBuild>(responseContent));
        }