Running Python script to deploy from MSBuild - python-2.7

I have a python script that is doing some deployment.
I want to run that script from msbuild and get the output in case it pass, or failed.
So, how can I communicate to msbuild of the status , and the error text?
I want to show the result on the build server.
I have to use python 2.7, and cannot use 3.x

Run the command using the Exec task and capture it's output. For example:
<Target Name="GetPythonOutput">
<PropertyGroup>
<PyCommand>/path/to/python.exe -a /path/to/pthonfile</PyCommand>
<TempFile>ExecTempFile</TempFile>
</PropertyGroup>
<Exec Command="$(PyCommand) > $(TempFile)" />
<ReadLinesFromFile File="$(TempFile)">
<Output TaskParameter="Lines" ItemName="PyOutput"/>
</ReadLinesFromFile>
<Delete Files="$(TempFile)" />
<Message Text="Python command output was: #(PyOutput)" />
</Target>
If you are using .Net 4.5 things are better since Exec can do most of the work for you

Related

Unable to execute sample axis2Client WSO2 EI 6.6.0

I am trying to use sample Axis2Client but I am facing an issue as below. I am following the page https://docs.wso2.com/display/EI6xx/Using+the+ESB+as+JMS+Consumer+and+Producer.
ant stockquote -Dmode=placeorder -Dtrpurl="jms:/StockQuoteProxy?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.ContentTypeProperty=Content-Type&transport.jms.DestinationType=queue"
Buildfile: /Users/user/WUM/wso2ei-6.6.0/samples/axis2Client/build.xml
init:
BUILD FAILED
/Users/user/WUM/wso2ei-6.6.0/samples/axis2Client/build.xml:307: /Users/user/WUM/wso2ei-6.6.0/wso2/lib/endorsed does not exist.
Total time: 0 seconds
How to fix this issue?
Could you please remove the following from the build.xml located in wso2ei-6.6.0/samples/axis2Client. Then try executing the same command again
<fileset dir="../../wso2/lib/endorsed">
<include name="*.jar"/>
</fileset>

gocd - making custom command script available to agent

I am trying to add a custom command which in turn calls a python script, as per example here https://support.thoughtworks.com/hc/en-us/articles/213253646-Go-s-custom-command,
<exec command="myecho.sh">
</exec>
In my case,
<exec command="/usr/bin/python cd_dashboard.py">
<arg>-v</arg>
</exec>
But when I execute the pipeline it fails with following error,
[go] Task: "/usr/bin/python cd_dashboard.py" -vtook: 0.2s
Error happened while attempting to execute '/usr/bin/python cd_dashboard.py -v'.
Please make sure [/usr/bin/python cd_dashboard.py] can be executed on this agent.
So the question is where should the python script reside to be accessible to agent? Should be in agent's PATH.
Is this correct understanding?
The command should be /usr/bin/python, please move cd_dashboard.py to the args. Right now GoCD trying to run executable /usr/bin/python cd_dashboard.py, which of course doesn't exist. You should have something like this:
<exec command="/usr/bin/python">
<arg>-v</arg>
<arg>cd_dashboard.py</arg>
</exec>

.Net Core 2 not building my SPA because it can't Exec properly?

I have created an React+Redux using the .Net Core 2.0 template. I didn't change anything yet it's not buildind.
Severity Code Description Project File Line Suppression State
Warning MSB3073 The command "node --version" exited with code
1. WebApplication2 C:\Tests\WebApplication2\WebApplication2\WebApplication2.csproj 25
Yet, node is properly installed, when I run "node --version" in a prompt (from any drive/directory) I get v8.4.0 and no error code (the expected behaviour).
I tried using the full path in the .csproj file.
<Exec Command=""C:\Program Files\nodejs\node" --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
And I'm still getting the same error
Severity Code Description Project File Line Suppression State
Warning MSB3073 The command ""C:\Program Files\nodejs\node" --version"
exited with code
1. WebApplication2 C:\Tests\WebApplication2\WebApplication2\WebApplication2.csproj 25
I reinstalled NodeJS, with the same results.
Then I even tried a dummy task calling dos echo 0 and it still fails.
Severity Code Description Project File Line Suppression State
Warning MSB3073 The command "echo 0" exited with code
1. WebApplication2 C:\Tests\WebApplication2\WebApplication2\WebApplication2.csproj 25
What's going on?
Here's the whole segment which does the check:
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
<!-- Ensure Node.js is installed -->
<Exec Command=""C:\Program Files\nodejs\node" --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<!-- In development, the dist files won't exist on the first run or when cloning to
a different machine, so rebuild them if not already present. -->
<Message Importance="high" Text="Performing first-run Webpack build..." />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
<Exec Command="node node_modules/webpack/bin/webpack.js" />
</Target>
This had been related to security issue of some sort.
Running "dotnet run" from a command prompt run with admin rights "fixed" the issue.
I ran into this issue (I realized that my node_modules folder wasn't there) so I upgraded my .Net Core app to 2.1 and ran npm i and that worked.
Doesn't hurt to just try npm i and try again

Checkstyle error on Unix only

I'm using Ant to run a custom regex based checkstlye for */.html files. It's very simple config.
Ant build.xml:
<taskdef resource="checkstyletask.properties" classpath="checkstyle-5.5-all.jar"/>
<target name="check">
<checkstyle config="checks.xml" failOnViolation="false">
<fileset dir="${basedir}" includes="**/*.html"/>
<formatter type="plain"/>
<formatter type="xml" toFile="${basedir}/reports/checkstyle-report.xml"/>
</checkstyle>
</target>
checks.xml:
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="RegexpMultiline">
<property name="format" value="\A.+<table>.+<\/table>.+\Z"/>
</module>
</module>
On Windows 7 64bit:
Apache Ant(TM) version 1.8.3 compiled on February 26 2012,
BUILD SUCCESSFUL
Total time: 1 second
On CentOS 64bit:
Apache Ant(TM) version 1.8.2 compiled on May 13 2011,
BUILD FAILED
build.xml:8: Unable to create a Checker: cannot initialize module RegexpMultiline - Unable to instantiate RegexpMultiline
Can anyone suggest something?
Thanks,
Ok, so simply running ant -v revealed the following:
parsing buildfile jar:file:/usr/share/java/ant-1.8.2.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/usr/share/java/ant-1.8.2.jar!/org/apache/tools/ant/antlib.xml from a zip file
...
[checkstyle] checkstyle version 4.4
[checkstyle] compiled on Mon December 06 2010, 21:35 GMT
So the reason for the failure is not so much to do with the OS, as the version & configuration of the Ant installation.
I think what's happening is that the v4.4 checkstyle is being picked up from
/usr/share/java/ant-1.8.2.jar!/org/apache/tools/ant/antlib.xml
in preference to what is specified in build.xml:
<taskdef resource="checkstyletask.properties" classpath="${basedir}/checkstyle/checkstyle-5.5-all.jar"/>
Update:
I didn't find checkstyle.jar in /usr/share/ant/lib/, but there was one in /usr/share/java/
Not sure how Ant was picking that up, but this is what has finally fixed the issue:
yum remove checkstyle4.noarch
Now Ant is free to use the .jar from the project!
Others may find this stackoverflow question relevent

nunit console is not telling what tests got failed

I recently moved out of nunit tag and moved to exec tag to run nunit console for running unit tests.
Here is what i have in my build script:
exec program="nunit-console.exe" verbose="true" failonerror="true">
arg file="../abc.dll"/>
exec>
Here is what I see in output:
task name="exec">250.0064250.0064
As you can see it did run from the duration and I know that my tests are currently failing but my build didn't fail.
Any ideas?
To be honest: I'm clueless. We're executing NUnit console through NAnt's <exec> task, we're getting meaningful output and we're absolutely not doing anything fancy:
<exec program="C:\dev\tools\NUnit\2.5.9\bin\net-2.0\nunit-console.exe">
<arg file="C:\foo\bar.dll" />
</exec>