/// <summary> /// Conditionally Write To Journal if there were packages that may need to be cleaned up during retention /// </summary> /// <param name="deployment"></param> /// <param name="wasSuccessful">Was the command successful. Usually ExitCode == 0</param> /// <param name="packageFile">Since package references can still be passed by the command line this needs to be provided here. /// Can remove once we obtain all references through variables</param> public void AddJournalEntry(RunningDeployment deployment, bool wasSuccessful, string packageFile = null) { var semaphore = SemaphoreFactory.Get(); var journal = new DeploymentJournal(fileSystem, semaphore, deployment.Variables); var hasPackages = !String.IsNullOrWhiteSpace(packageFile) || deployment.Variables.GetIndexes(SpecialVariables.Packages.PackageCollection).Any(); var canWrite = deployment.Variables.Get(SpecialVariables.Tentacle.Agent.JournalPath) != null; if (canWrite && hasPackages && !deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, wasSuccessful)); } }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(retentionPolicySet, "No retention-policy-set was specified. Please pass --retentionPolicySet \"Environments-2/projects-161/Step-Package B/machines-65/<default>\""); if (days <=0 && releases <= 0) throw new CommandException("A value must be provided for either --days or --releases"); var variables = new CalamariVariableDictionary(); variables.EnrichWithEnvironmentVariables(); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var deploymentJournal = new DeploymentJournal(fileSystem, new SystemSemaphore(), variables); var clock = new SystemClock(); var retentionPolicy = new RetentionPolicy(fileSystem, deploymentJournal, clock); retentionPolicy.ApplyRetentionPolicy(retentionPolicySet, days, releases); return 0; }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(packageFile)) throw new CommandException("Could not find package file: " + packageFile); Log.Info("Deploying package: " + packageFile); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); var outputVariables = new VariableDictionary(outputVariablesFile); variables.MergeWith(outputVariables); var scriptCapability = new CombinedScriptEngine(); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var substituter = new FileSubstituter(fileSystem); var configurationTransformer = new ConfigurationTransformer(variables.GetFlag(SpecialVariables.Package.IgnoreConfigTransformationErrors), variables.GetFlag(SpecialVariables.Package.SuppressConfigTransformationLogging)); var embeddedResources = new CallingAssemblyEmbeddedResources(); var iis = new InternetInformationServer(); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables), new ServiceMessageCommandOutput(outputVariables))); var semaphore = new SystemSemaphore(); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var conventions = new List<IConvention> { new ContributeEnvironmentVariablesConvention(), new ContributePreviousInstallationConvention(journal), new LogVariablesConvention(), new AlreadyInstalledConvention(journal), new ExtractPackageToApplicationDirectoryConvention(new LightweightPackageExtractor(), fileSystem, semaphore), new FeatureScriptConvention(DeploymentStages.BeforePreDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, scriptCapability, fileSystem, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptCapability, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterPreDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer), new ConfigurationVariablesConvention(fileSystem, replacer), new CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureScriptConvention(DeploymentStages.BeforeDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptCapability, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, scriptCapability, fileSystem, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new LegacyIisWebSiteConvention(fileSystem, iis), new FeatureScriptConvention(DeploymentStages.BeforePostDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptCapability, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, scriptCapability, fileSystem, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterPostDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); try { conventionRunner.RunConventions(); outputVariables.Save(); if (!deployment.SkipJournal) journal.AddJournalEntry(new JournalEntry(deployment, true)); } catch (Exception) { if (!deployment.SkipJournal) journal.AddJournalEntry(new JournalEntry(deployment, false)); throw; } return 0; }