Running Powershell Script after Build automatically - visual-studio

My question is that how can I trigger a powershell script when I check-in a code in VS2013 automatically.
see what I have done till now is that as soon as I check in a build is triggered. Separately I have a PS script that I run after the build succeeds, now what i want is that the script should run automatically as soon as the build succeeds, and i do not have to do anything to trigger the sript

If you are using XAML build in tfs, you can specify the path to a custom script in Build Definition--2.Build--5.Advanced--Post-build script path, which will run after the MSBuild activity successfully completes.
If you are using the windows build agent, then you can simply add a PowerShell build step after the build step. See: https://msdn.microsoft.com/en-us/Library/vs/alm/Build/scripts/index#env_vars

Related

Automatic Firefox build on Windows(Jenkins)

I am trying to create a job for Jenkins to automatically build Firefox on Windows machine.
Is it possible to create a script(.bat, .sh or python) which starts start-shell.bat and executes mach build command inside started shell window?
Create a new freestyle job and then configure it. After specifying where your source code repository is located in the SCM section. Add a Window Batch Build step and specify the workspace-relative path to your .bat file that in turn calls the commands you want.

How to run script shell before building on Jenkins

(Jenkins newb-newb-newbie here)
Hi there.
I have a Maven project, deployed on Jenkins . In this project, I have an integration test, which depends on a .Net server in order to be run correctly.
The problem is, when I'm trying to build my project on Jenkins, the integration test fails, because the .Net isn't launched...
I need to execute a shell script (for launhing the .Net server) before building my project.
So my question is : how can I launch a script of my project before building from Jenkins?
Theres a build step Execute Windows batch command which you could use to start your server.
You might have to use START to have it launched in a separate process, so your build continues without waiting for the server process to finish, and you might need to put in some delay in case your server needs some time to settle before your tests can run.
You might also need to kill your server after your tests are done, you might be able to use tasklistand taskkill in another Execute Windows batch command build step, and some batch magic to do this.

Single Team Foundation command exits build step after execution in Jenkins

When executing Team Foundation commands in a free-style Jenkins job on a Windows Slave (within a 'Execute Windows Batch command' section), the successful execution of a command will cause that build step of batch commands to exit regardless of whether there are other commands remaining after the tf.cmd call.
For example, to create a new workspace and then map that workspace, I need 2 individual instances of 'Execute Windows Batch command' build steps. Placing both these commands in the same build step will result in only the first being executed.
Does anyone know why this might be happening and how to resolve it (other than the current workaround of many build steps).
Thanks.
Note: The TF plugin does not fit my needs for this particular Jenkins job because the plugin does not allow gets from labels.
Since there isn't another answer for a while, I recently found a different workaround that resolves this issue a bit nicer.
When calling the tf.cmd, use call before the command. This allows multiple tf commands to be executed in the same Jenkins window.
Example:
call tf.cmd workspaces /format:brief /server:http://servername

Execute Shell Script after post build in Jenkins

I am trying to execute a shell script if either the build pass or fails after post-build in Jenkins. I cannot see this option in post build to execute some shell script except for running a target.
Very easily done with Post build task plugin.
You can also run arbitrary commands using the Groovy Post Build - and that will give you a lot of control over when they run and so forth. We use that to run a 'finger of blame' shell script in the case of failed or unstable builds.
if (manager.build.result.isWorseThan(hudson.model.Result.SUCCESS)) {
item = hudson.model.Hudson.instance.getItem("PROJECTNAMEHERE")
lastStableBuild = item.getLastStableBuild()
lastStableDate = lastStableBuild.getTime()
formattedLastStableDate = lastStableDate.format("MM/dd/yyyy h:mm:ss a")
now = new Date()
formattedNow = now.format("MM/dd/yyyy h:mm:ss a")
command = ['/appframe/jenkins/appframework/fob.ksh', "${formattedLastStableDate}", "${formattedNow}"]
manager.listener.logger.println "FOB Command: ${command}"
manager.listener.logger.println command.execute().text
}
(Our command takes the last stable build date and the current time as parameters so it can go investigate who might have broken the build, but you could run whatever commands you like in a similar fashion)
If I'm reading your question right, you want to run a script in the post build actions part of the build.
I myself use PostBuildScript Plugin for running git clean -fxd after the build has archived artifacts and published test results. My Jenkins slaves have SSD disks, so I do not have the room keep generated files in the workspace.
You should be able to do that with the Batch Task plugin.
Create a batch task in the project.
Add a "Invoke batch tasks" post-build option selecting the same project.
An alternative can also be Post build task plugin.
You'd have to set up the post-build shell script as a separate Jenkins job and trigger it as a post-build step. It looks like you will need to use the Parameterized Trigger Plugin as the standard "Build other projects" option only works if your triggering build is successful.

what's the best way to automate post-build actions?

We use Luntbuild to do our builds. Our project builders are in Maven 2. After each build is done we need to do a lot of cd, mkdir, cp, unzip rm and zip commands. We currently have a shell scrip that does this but we need to wait for a successful build and then manually run that script. Is there a way to set luntbuild to do the post-build actions for us as soon as it gets a successful build.
If so what should the format of the post-build script be? and how do i set it up?
You may want to run your script via the maven invoker plugin. There is also an example on their site.

Resources