Bamboo, NAnt, and PSExec shows no Console UI - console

I need NAnt to kick off a long running console app on the local machine during a Bamboo build. It does this correctly but without the console UI. Rather than try to show all that, I have worked it down to a trivial example that also does not show the UI.
When I type the following:
C:\PSExecPath\psexec -d -i ping localhost
or
C:\PSExecPath\psexec \\localmachinename -d -i ping localhost
I get exactly the results one would expect including the UI.
But when this same command is kicked off from NAnt there is no UI. For example when the following build file is run by NAnt after being started with Bamboo:
<?xml version="1.0"?>
<project default="all">
<target name="all">
<exec program="C:\PSExecPath\psexec.exe" spawn="true">
<arg value="\\localmachinename" />
<arg value="-d" />
<arg value="-i" />
<arg value="ping" />
<arg value="localhost" />
</exec>
</target>
</project>
Just to make sure it is stated, NAnt is being executed in the same profile.

Bamboo was running as a Service. I changed it to run as a Console and everything started running as expected.

Related

Cannot run program npm error when running Cordite network map JAR on Windows

When running the network map using Java (as described here: https://gitlab.com/cordite/network-map-service#using-java) on Windows, I get the following error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-antrun-plugin:1.8:run (build-website)
on project network network-map-service: An Ant BuildException has
occured: Execute failed: java.io.IOException: Cannot run program
"npm": CreateProcess error-2, The system cannot find the file
specified around Ant part ...... # 4:45 in
C:\Users\x.x\network-map-service\target\antrun\build-main.xml
What is the cause of this error?
You are encountering this issue because the build file is as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main" >
<target name="main">
<exec failonerror="true" executable="npm">
<arg value="install"/>
<arg value="-g"/>
<arg value="brunch"/>
</exec>
<exec failonerror="true" dir="website" executable="npm">
<arg value="install"/>
</exec>
<exec failonerror="true" dir="website" executable="brunch">
<arg value="build"/>
</exec>
</target>
</project>
But Windows requires the executable names to be npm.bat and brunch.bat instead.
If you change the executable names in the build file, it will work correctly.

ASP.NET Web Application (MVC) Deployment Automation and Subversion

We are trying to automate the build process to our staging servers but have run into a snag, albeit fairly minor. We are using the Publish functionality built into VS2010, committing to Subversion, and then a 3rd party app (Beanstalk) automatically pulls the updated files and FTPs them to the Staging server.
The problem we've run into is that we only appear to have the following choices:
(Lesser of 2 evils) If we choose to use "Replace matching files with local copies", this works great, with one exception: this option does not delete any files that were deleted from the project. This will lead to junk and/or security issues for unkempt files from the days of old.
If we choose to use "Delete all existing files prior to publish", this deletes the entire folder structure, including the .SVN hidden folders that Subversion uses for Update tracking, etc. This seems like the best solution from an accuracy standpoint, but it really destroys the local SVN environment, which is the middle-man for this automation.
My question: Is there an easy work around for this, or a totally different deployment option we're overlooking (we do not want to publish directly to the server from VS, as we want to track who/what/when a deployment takes place)? The only thing I've come across is to delete the file contents manually prior to publishing, while leaving the folder structure intact, then deploying with "Replace matching files with local copies". Unfortunately, this brings on a whole new meaning of the word "automation".
Any ideas on how best to accomplish this?
You may want to consider using NAnt or something similar for tasks you wish to automate, like building and publishing to Subversion. This is most of my build file for a WebApplication Project. It might be different for MVC. If so, I'm sure you can use this as a starting point. I am by no means an NAnt expert so there may be some flaws, but this is definitely working for me.
I had to add a PublishToFileSystem target to each .csproj file I wanted to publish. The source for that can be found here.
Build file also available on Pastebin
<?xml version="1.0"?>
<project name="deploy" default="all">
<property name="nant.settings.currentframework" value="net-4.0" />
<!-- Any of these can be passed through the command line -->
<property name="sourceDirectory" value="${project::get-base-directory()}" />
<property name="publishDirectory" value="${sourceDirectory}\build" />
<property name="MSBuildPath" value="${framework::get-assembly-directory(framework::get-target-framework())}\msbuild.exe" />
<!-- The build configuration to use when publishing and transforming the web.config file. This is useful when you have multiple environments for which you create builds -->
<property name="buildConfiguration" value="Release" />
<!-- Set these as needed -->
<property name="svn.username" value="" />
<property name="svn.password" value="" />
<target name="SvnPrep">
<property name="svn.dir" value="${publishDirectory}\.svn" />
<property name="svn.update" value="true" readonly="false" />
<echo>env.svn.path = svn</echo>
<echo>svn.dir = ${svn.dir}</echo>
<mkdir dir="${publishDirectory}" unless="${directory::exists(publishDirectory)}" />
<!-- Check if there's a .svn dir already. If not: checkout, else: update. -->
<if test="${not directory::exists(svn.dir)}">
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='co ${svn.builduri} --username ${svn.username} --password ${svn.password} --non-interactive ./' />
</exec>
<property name="svn.update" value="false" readonly="false" />
</if>
<if test="${svn.update}">
<exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
<arg line='up --username ${svn.username} --password ${svn.password} --non-interactive --force ./' />
</exec>
</if>
<!-- Force any conflicts to be resolved with the most recent code -->
<exec program='svn.exe' workingdir="${publishDirectory}\" verbose="true">
<arg line='resolve --accept theirs-full -R ./' />
</exec>
</target>
<target name="DeleteFiles">
<!-- Delete only the files (retain directory structure) in the directory to which you are going to publish/build. NAnt excludes svn directories by default. -->
<delete includeemptydirs="false">
<fileset basedir="${publishDirectory}">
<include name="**/*.*" />
</fileset>
</delete>
</target>
<target name="Publish">
<!-- I know there's an MSBuild task, I don't know why I didn't use it, but this works. -->
<!-- Build and publish frontend -->
<exec program="${MSBuildPath}">
<arg line='"${sourceDirectory}\YourProject.csproj"' />
<arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
<arg value="/target:PublishToFileSystem" />
</exec>
<!-- Transform the correct web.config and copy it to the build folder. PublishToFileSystem doesn't transform the web.config, unfortunately. -->
<exec program="${MSBuildPath}">
<arg line='"${sourceDirectory}\YourProject.csproj"' />
<arg value='"/p:Platform=AnyCPU;Configuration=${buildConfiguration};PublishDestination=${publishDirectory}"' />
<arg value="/target:TransformWebConfig" />
</exec>
<copy file="${sourceDirectory}\YourProject\obj\${buildConfiguration}\TransformWebConfig\transformed\Web.config" tofile="${publishDirectory}\YourProject\web.config" overwrite="true" />
</target>
<target name="SvnCommit">
<!-- add any new files -->
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='add --force .' />
</exec>
<!-- delete any missing files, a modification of this http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn -->
<!-- When there's nothing to delete it looks like this fails (to NAnt) but it is actually fine, that's why failonerror is false -->
<exec program='cmd.exe' workingdir="${publishDirectory}\" verbose="true" failonerror="false"
commandline='/C for /f "usebackq tokens=2*" %i in (`svn status ^| findstr /r "^\!"`) do svn del "%i %j"' >
</exec>
<exec program='svn.exe' workingdir="${publishDirectory}" verbose="true">
<arg line='commit -m "Automated commit from build runner"' />
</exec>
</target>
<target name="ShowProperties">
<script language="C#" prefix="util" >
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
foreach (DictionaryEntry entry in project.Properties)
{
Console.WriteLine("{0}={1}", entry.Key, entry.Value);
}
}
]]>
</code>
</script>
</target>
<target name="all">
<call target="ShowProperties" />
<call target="SvnPrep" />
<call target="DeleteFiles" />
<call target="Publish" />
<call target="SvnCommit" />
</target>
</project>
We also deploy out of SVN and ran into the same problem. Our solution is to essentially branch the project for "significant" upgrades -- situations where we were adding and deleting files, not just fixing small bugs and making tweaks which you can usually handle by xcopy. Svn layout looks like:
--project
---production
----20100101
----20100213
[etc, etc]
Procedure-wise, it is pretty simple -- if there are big enough changes, check in build artifacts as appropriate.
Another thing you might want to try, especially if you cannot get your production bits to "switch" branches easily, would be to use something fancier such as powershell to execute the delete files command, that could filter out the *.svn folders.
I would say "fortunately" this brings a whole new meaning to the word automation :) What you're describing is knows as Application Release Automation, also sometimes called Deployment Automation. If you really want to know who did what and where, what was the outcome, etc. then you are looking for a product like Nolio ASAP (http://www.noliosoft.com). Please let me know if this helps, since from what you're describing, it seems like a perfect match.
+Daniel
Why are you publishing the site to a folder that is handled by Subversion?
The way I would do it is work directly with the files in the SVN handled folders. As soon as I commit anything, it gets pulled by beanstalk to the staging area. This way, files deleted are always deleted from the repo and you don't have to worry about that. Everything is always in sync.
If you feel that this is putting too many files to the staging area, you can still use scripts and Visual Studio commands to publish the site. But I'm not sure how well Beanstalk integrates with this scenario. I know CC.net and many other alternatives do.

NAnt and ASP.NET Compiler

I have a build script running successfully, but I am having a hard time running anything after aspnet_compiler completes. I want to use robocopy to copy the project to another folder. If I put the copy task above the compile (as shown below) I get the message to the console, but if I place it after the compile it is not seen. Am I missing something? Do I need to check for a return code from the compiler to call tasks after its completion?
<target name="copy" depends="init">
<echo message="This is my message for robocopy..."/>
</target>
<target name="compile" depends="copy">
<exec program="${msbuild.exe}"
commandline='MySolution.sln /p:Configuration=${Configuration};OutDir="${build.dir}\\"' />
</target>
<target name="precompile-web" depends="compile">
<exec program="${aspnet_compiler.exe}"
commandline='-v /MyProj-p "${build.dir}"\_PublishedWebsites\MyProj.Web'
/>
And yes, when/if I move the copy task below precompile-web I change the depends="precompile-web" and the compile task depends to "init".
If I understand you correctly here, you want to:
Copy the files
Compile them using MSBuild
Precompile them for the web
Is that right? I would have thought you'd want to do it this way around:
Compile the files using MSBuild
Precompile them for the web
Copy the files somewhere else (for use by IIS, etc)
If my way is correct, then I'd guess you'd want your targets to reference each other like this?
<target name="compile-and-publish" depends="compile,precompile-web,copy" />
<target name="compile">
<exec program="${msbuild.exe}" commandline='MySolution.sln /p:Configuration=${Configuration};OutDir="${build.dir}\\"' />
</target>
<target name="precompile-web">
<exec program="${aspnet_compiler.exe}" commandline='-v /MyProj-p "${build.dir}"\_PublishedWebsites\MyProj.Web' />
</target>
<target name="copy" depends="init">
<echo message="This is my message for robocopy..."/>
</target>
This way, you're not pinning each of your targets down to relying upon other targets (for re-use) but you get the order that you need to achieve the job at hand.
Any good to you?

Custom Flex Ant build task

A beginner's question.
I'm building a .swf with Flex Ant.
To my .swf I link a file, target.as, which I generate from file source.txt with command
./tool.sh source.txt > target.as
How can I add what is described in the above sentence to my ant build process?
The exec task executes any external program:
<exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as">
<arg path="source.txt"/>
</exec>
So if you use the mxmlc ant task to compile your swf, you can define your build task like this:
<target name="build">
<exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as">
<arg path="source.txt"/>
</exec>
<mxmlc ....>
...
</mxmlc>
</target>
To run that command in Ant use the exec task.
<exec executable="tool.sh" dir="toolshdir" output="target.as">
<arg value="source.txt" />
</exec>
http://livedocs.adobe.com/flex/3/html/anttasks_1.html
You may also want to use the Flex "mxmlc" task instead of calling it with exec. You can do a lot of configuration right within the XML if you'd prefer not to have to maintain the shell script.

Using the aspnet_compiler.exe to compile .Net Web Apps

I have code in the top layer of my .Net web application that I'd like to unit test, but when my build server compiles the project using the aspnet_compiler.exe, it makes a .dll file that is not at all usable by another project, i.e. an NUnit test project.
(This is true of ASP .Net web applications and of ASP .Net MVC applications.)
Am I doing something wrong here? Here's my NAnt script that calls the compiler...
<exec program="${asp.compiler.home}/aspnet_compiler.exe" failonerror="true">
<arg value="-nologo"/>
<arg value="-c"/>
<arg value="-f"/>
<arg value="-errorstack"/>
<arg value="-v"/>
<arg value="${project.name}"/>
<arg value="-p"/>
<arg value="${project::get-base-directory()}"/>
<arg value="${web.deploy.dir}\${project.name}"/>
</exec>
I have code in the top layer of my .Net web application that I'd like to unit test [...]
Stop right there; that's the problem. Put that code into a helper, and test it outside of ASP.NET.
You don't need to use aspnet_compiler.exe. That is just a utility application for precompiling your aspx pages to avoid the startup lag when a user hits a page for the first time.
As I understand it, any non-aspx/ascx code in your ASP.NET MVC web application will be compiled normally into a DLL when your solution is built. This DLL is then usable by your NUnit test project. I assume it's those bits you want to test.
So, just build the project using MSBuild from NAnt and forget about aspnet_compiler.exe.
Can't you run something like here, instead of in Nant as a post-build event?
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -v / -p "$(SolutionDir)\PathToMyWebProject"
(where FilePathToMyWebProject is the path to your project file relative to the solution file)
We use MSBuild with a build file to compile the web app and run tests, if you can skip the NAnt stuff, here is a relevent section from the build file (called as a parameter to MSbuild.exe):
<!-- Build projects by calling the Project files generated by VS -->
<Target Name="Build">
<MSBuild Projects="$(ProjectFile)" />
<MSBuild Projects="$(TestProjectFile)" />
</Target>
<!-- Run Unit tests -->
<Target Name="Test" DependsOnTargets="Build">
<CreateItem Include="ClearViewTest\Bin\Debug\ClearViewTest.exe">
<Output TaskParameter="Include" ItemName="ClearViewTest" />
</CreateItem>
<NUnit Assemblies="#(ClearViewTest)" ToolPath="C:\Program Files\NUnit 2.4\bin" ContinueOnError="false" OutputXmlFile="SoultionTestResults.xml" />
</Target>

Resources