Example #1
0
        public IArtifactDetails GetArtifactDetails(IExecutionContext context, AgentArtifactDefinition agentArtifactDefinition)
        {
            ArgUtil.NotNull(context, nameof(context));
            ArgUtil.NotNull(agentArtifactDefinition, nameof(agentArtifactDefinition));

            Trace.Entering();

            ServiceEndpoint vssEndpoint = context.Endpoints.FirstOrDefault(e => string.Equals(e.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));

            ArgUtil.NotNull(vssEndpoint, nameof(vssEndpoint));
            ArgUtil.NotNull(vssEndpoint.Url, nameof(vssEndpoint.Url));

            var            artifactDetails = JsonConvert.DeserializeObject <Dictionary <string, string> >(agentArtifactDefinition.Details);
            VssCredentials vssCredentials  = VssUtil.GetVssCredential(vssEndpoint);
            var            tfsUrl          = context.Variables.Get(WellKnownDistributedTaskVariables.TFCollectionUrl);

            Guid projectId = context?.Variables.System_TeamProjectId ?? Guid.Empty;

            if (artifactDetails.ContainsKey("Project"))
            {
                Guid.TryParse(artifactDetails["Project"], out projectId);
            }

            ArgUtil.NotEmpty(projectId, nameof(projectId));

            string relativePath;
            string accessToken;

            vssEndpoint.Authorization.Parameters.TryGetValue(EndpointAuthorizationParameters.AccessToken, out accessToken);

            if (artifactDetails.TryGetValue("RelativePath", out relativePath))
            {
                var buildArtifactDetails = new BuildArtifactDetails
                {
                    Credentials  = vssCredentials,
                    RelativePath = artifactDetails["RelativePath"],
                    AccessToken  = accessToken,
                    Project      = projectId.ToString(),
                    TfsUrl       = new Uri(tfsUrl)
                };

                if (artifactDetails.ContainsKey("DefinitionName"))
                {
                    buildArtifactDetails.DefinitionName = artifactDetails["DefinitionName"];
                }

                if (artifactDetails.ContainsKey("DefinitionId"))
                {
                    buildArtifactDetails.DefintionId = Convert.ToInt32(artifactDetails["DefinitionId"], CultureInfo.InvariantCulture);
                }

                return(buildArtifactDetails);
            }
            else
            {
                throw new InvalidOperationException(StringUtil.Loc("RMArtifactDetailsIncomplete"));
            }
        }
        public ContainerProviderFactory(BuildArtifactDetails buildArtifactDetails, string rootLocation, int containerId, IExecutionContext executionContext)
        {
            this._buildArtifactDetails = buildArtifactDetails;
            this._rootLocation         = rootLocation;
            this._containerId          = containerId;
            this._executionContext     = executionContext;

            var executionLogger = new ExecutionLogger(executionContext);

            var httpRetryOnTimeoutOptions = new HttpRetryOnTimeoutOptions
            {
                MaxRetries         = 5,
                MinBackoff         = TimeSpan.FromSeconds(30),
                BackoffCoefficient = TimeSpan.FromSeconds(10),
            };

            _retryOnTimeoutMessageHandler = new HttpRetryOnTimeoutMessageHandler(
                httpRetryOnTimeoutOptions,
                executionLogger);
        }