Esempio n. 1
0
        /// <summary>
        /// This common codes is to invoke post deployment operations.
        /// It is written to require least dependencies but framework assemblies.
        /// Caller is responsible for synchronization.
        /// </summary>
        /// <param name="kind">MSDeploy, ZipDeploy, Git, ..</param>
        /// <param name="requestId">for correlation</param>
        /// <param name="status">Success or fail</param>
        /// <param name="details">deployment specific json</param>
        /// <param name="tracer">tracing</param>
        public static async Task InvokeWithDetails(string kind, string requestId, string status, string details, TraceListener tracer)
        {
            DeploymentCompletedInfo.Persist(System.Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"), kind, requestId, status, details);

            if (string.Equals("Success", status, StringComparison.OrdinalIgnoreCase))
            {
                await Invoke(requestId, tracer);
            }
        }
Esempio n. 2
0
        public static void Persist(string siteName, string kind, string requestId, string status, string details)
        {
            var info = new DeploymentCompletedInfo
            {
                TimeStamp = $"{DateTime.UtcNow:s}Z",
                SiteName  = siteName,
                Kind      = kind,
                RequestId = requestId,
                Status    = status,
                Details   = details ?? string.Empty
            };

            try
            {
                var path       = Path.Combine(System.Environment.ExpandEnvironmentVariables(@"%HOME%"), "site", "deployments");
                var file       = Path.Combine(path, $"{Constants.LatestDeployment}.json");
                var serializer = new JavaScriptSerializer();
                var content    = serializer.Serialize(info);
                FileSystemHelpers.EnsureDirectory(path);

                // write deployment info to %home%\site\deployments\LatestDeployment.json
                OperationManager.Attempt(() => FileSystemHelpers.Instance.File.WriteAllText(file, content));

                // write to etw
                KuduEventSource.Log.DeploymentCompleted(
                    info.SiteName,
                    info.Kind,
                    info.RequestId,
                    info.Status,
                    info.Details);
            }
            catch (Exception ex)
            {
                KuduEventSource.Log.KuduException(
                    info.SiteName,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    $"{ex}");
            }
        }