Is there a way to have every scheduled task that is created so that a task always runs before and after - windows-server-2008

I'm trying to save data to a database before a scheduled task runs and after it has finished running so that I can monitor a number of things.
I can manually add an extra action before and after each task, but I can't guarantee other users will do the same.
Is there some way, for all tasks including new tasks created in the future, to always run these other actions before and after?
I'm using WIN 2008 R2.

Graham,
Yes, that's possible, by adding more than 1 action sets as follows-
<Actions Context="Author">
<Exec>
<Command>C:\Windows\System32\wscript.exe</Command>
<Arguments>u:\Scripts\Pre_test.vbs</Arguments>
</Exec>
<Exec>
<Command>C:\Windows\System32\wscript.exe</Command>
<Arguments>u:\Scripts\test.vbs</Arguments>
</Exec>
<Exec>
<Command>C:\Windows\System32\wscript.exe</Command>
<Arguments>u:\Scripts\Post_Test.vbs</Arguments>
</Exec>
</Actions>
Let me know if it worked.

Related

Expose MSBuild property in Cake script after build step

Can you get property set by MSBuild inside your cake script?
I currently have a target that runs after compilation to indicate whether it has run, or whether it was an incremental build.
I want to detect in the remainder of my cake build whether incremental build took place.
The target that I currently use on my MSBuild is as follows:
<!-- Defines Targets that should be run after Compile, but skipped if Compile doesn't take place -->
<PropertyGroup>
<TargetsTriggeredByCompilation>
$(TargetsTriggeredByCompilation);
EnablePostBuild
</TargetsTriggeredByCompilation>
</PropertyGroup>
<Target Name="EnablePostBuild">
<!-- Disable post build actions -->
<PropertyGroup>
<SkipPostBuildActions>false</SkipPostBuildActions>
</PropertyGroup>
</Target>
If I trigger the build in Cake as follows:
var buildSettings = new MSBuildSettings()
.WithProperty("SkipPostBuildActions", "true")
MSBuild("./src/Application.sln",buildSettings );
var SkipPostBuildActionsVal = buildSettings??
Can I get the value of SkipPostBuildActions after the MSBuild step?
This is actually not much of a Cake problem: Cake "only" runs msbuild using the given parameters.
So, if you find a way how to access a Property from outside msbuild you can transfer that solution to Cake.
AFAIK msbuild does not even support easy sharing of property-modifications between tasks, let alone outside the msbuild-process.
I see two possible solutions:
Output the value of SkipPostBuildActions into the log, using the Message-Task then set a FileLogger on your msbuild-call and parse the log-file afterwards.
Output the value of SkipPostBuildActions to a dedicated file using the WriteLinesToFile-Task then parse that file after msbuild has run.
Personally I'd chose the latter option.

How to add a specific post build action in jenkins for multiple jobs in one shot?

I need to add a post-build action(Deploy to container) to 23 jobs at a time. Is there a plugin to do that to make my work easy?
You have two solutions:
Either you update the post-build actions for each Job
Either you are able to script your post-build action using Postbuildscript's plugin: https://plugins.jenkins.io/postbuildscript And you call this script in your post-build action
Benefit of the second solution, is that you will have to update your job's configuration only once. Then you only need to maintain your script.

In-flight update - How to make MSI wait for the executable to exit before updating?

I'm trying to do an in-flight update in our app. That means, I'm downloading an update, calling msiexec and exit in a reasonable time (less then a second). The MSI does the update and resumes the transaction by calling the updated version with a token passed to it. This actually works fine if I don't update the main executable.
The problem I have is that even though the calling app exits fairly quickly and the MSI seems to need some time before it actually gets to update the file, the main executable's update is deferred. I'm passing /noreboot (and /passive) to msiexec but that means that the app is "repaired" when launched next time. However since the app can be invoked directly (not through shortcuts) it needs to be updated properly.
So the question is, how can I make the windows installer wait for my app to quit before it checks whether it is locked or not?
I'm thinking right now that I could pass a process id to the installer and have a custom action (dll?) that waits for this, but I would like to avoid this for two reasons: 1) The app is already out there and it won't pass the process id and 2) I would like to find a solution that does not require me to write a DLL, if possible.
I'm using WiX to create the MSI setup.
Maybe this solution is a little to pragmatic but instead of starting msiexec from your main executable you could write a little helper tool.
Your main executable would call this helper which sleeps for a second or two and then calls msiexec while your main application is closing.
Another way could be to make use of the Wix-Utils:
Reference the Util-schema in your namespace:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
and configure it to ensure that your application is closed:
<util:CloseApplication Id="CloseApp" CloseMessage="yes" Target="MyApp.exe" RebootPrompt="no" />
For a full list of all options have a look at the documentation:
http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html

Counting how many script in SSIS have been completed

In SSIS package i have multiple scripts running within a job. At any given time i want to read how many scripts have been executed eg, 5/10 (50%) have been completed. Please tell how can i achieve that?
Currently there is no such functionality provided by SSIS to track progress of package execution.
It seems you need to write your own custom utility/application to implement same or use third party one.
There are few ways to do -
Using a switch called /Reporting or /Rep of DTEXEC at the command-line . For example:
DTEXEC /F ssisexample.dtsx /Rep P > progress.txt
2.Implement package logging or customize it.
3 . Implement Event handler on required executable. You can also use OnPipelineRowsSent log of Data Flow Task.
If you want to write your own application then below thread will provide nice starting point.
How do you code the Package Execution Progress window in C#
In my experience, we are using another software to monitor the jobs that are running. http://en.wikipedia.org/wiki/CA_Workload_Automation_AE
You can also try to create your own application that runs on the background that checks that status of your jobs, through checking the logs.

MsBuild - Is it possible to isolate batch tasks, so one failing task doesn't skip the remaining tasks?

Let me start by example... I have an all.proj that looks similar to this:
<ItemGroup>
<ProjectsToBuild Include="..\Sites\*\*.csproj" />
</ItemGroup>
<Target Name="DeployWebsites" DependsOnTargets="BuildMergedSolutions">
<AspNetCompiler
PhysicalPath="%(ProjectsToBuild.RootDir)%(ProjectsToBuild.Directory)"
TargetPath="%(ProjectsToBuild.RootDir)%(ProjectsToBuild.Directory)..\..\..\deploy\%(ProjectsToBuild.Filename)"
VirtualPath="/%(ProjectsToBuild.Filename)%(ProjectsToBuild.Extension)"
Debug="true"
Updateable="true"
Force="true" />
</Target>
If one of the tasks fails it will exit the target. Is there any way to just print the error and continue exceuting the remaining tasks?
ContinueOnError is not an option since it will just convert the errors to warnings. I want the build to fail in the end but I also want to get as much error information as I can get so I still need to compile all the sites even though some of them fail.
The only way you can do this is if you can detect when an error has occurred. Basically the task will have to write out some artifact, or present you an output parameter where you can tell if it failed or not. You would use that along with setting ContinueOnError to true for the task itself. The idea is, set ContinueOnError to true, allow all the task invocations to complete then after that look to see if there was an error and act accordingly.
I did something similar for executing unit tests from MSBuild. I wanted all the unit tests to execute in all test assemblies, but also wanted to fail the build after they were done. So what I did was set ContinueOnError to true, then searched the XML file that the results were written to for any failed test cases, also I aggregated the messages from that file.
In your case the AspNetCompiler task doesn't write out any such file. The AspNetCompiler is wrapping up the aspnet_compiler.exe utility by extending ToolTask (via ToolTaskExtension) so you could keep track of the ExitCode. It is kind of tricky without writing you own task extending that task. If you use Target Batching you could invoke the AspNetCompiler task and then write each ExitCode into a file. Then after that look through that file for and non-zero exit code. You may want to consider writing your own custom task which extends the AspNetCompiler task, should be pretty simple to write.
For more info on batching see the resources at http://sedotech.com/Resources#Batching.