示例#1
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);
        }