gocd - making custom command script available to agent - go-cd

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>

Related

Termux says "'Bad Interpreter: No such file or directory"

I have a problem and hope someone can help me. I am currently trying to write a script for Termux or Termux:Task. My script currently looks like this:
#!/data/data/com.termux/files/usr/bin/bash
cd /./sdcard/www/public/
wp post list sleep 5
Every time I load the script I get the following error message:
/data/data/com.termux/files/usr/bin/wp: /usr/bin/env: bad interpreter: No such file or directory.
I've been looking for a solution to my problem for hours, unfortunately without success.
I am using an extension for Termux called "WordPress CLI". When I start termux and enter the commands individually, everything works. But as soon as I write the commands into a sh script and start it doesn't work anymore. :(
Can anyone help me?
Thanks a lot
This is simple error you can fix it by replacing !/data/data/com.termux/files/usr/bin/bash. With #!/data/data/com.termux/files/usr/bin/bash
Please tell if you get error again
Try with #!/usr/bin/env bash in the shebang line.
Termux-exec allows you to execute scripts with shebangs for traditional Unix file structures. So shebangs like #!/bin/sh and #!/usr/bin/env python should be able to run without termux-fix-shebang.
From https://wiki.termux.com/wiki/Termux-exec
According to doc:
Why do I keep getting a '/bin/sh bad interpreter' error?
This error is thrown due to access script interpreter at nonexistent
location.
Termux does not have common directories like /bin, /sbin, /usr/bin at
their standard place. There is an exception for certain devices where
/bin is a symbolic link to /system/bin, but that does not make a
difference.
Interpreters should be accessed at this directory only:
/data/data/com.termux/files/usr/bin
There are three ways to fix this:
Install termux-exec by using pkg install termux-exec. It won’t affect the current session, but after a restart should work without
any setup. Not needed if your Termux is up to date. If still not
working, try the next workaround.
Use command termux-fix-shebang to fix the shebang line of specified file.
Use termux-chroot from package proot to setup a chroot environment mimicking a normal Linux file system in Termux.
termux-fix-shebang my_script.py of second method work for me, which it modify the shebang(first line of my_script.py) from #!/usr/bin/env python to #!/data/data/com.termux/files/usr/bin/env python. Since /usr/bin/ is not exist in Android, that's why it throws the error /usr/bin/env: bad interpreter: No such file or directory. The other solution is run with python my_script.py, neither of my_script.py nor ./my_script.py.
In my test, termux-exec of the first method only work if I added correct shebang in main script(child OR child of child script no need) and ran command export LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so.
And for the issue of this question, error shows /usr/bin/env in the middle with /data/data/com.termux/files/usr/bin/wp even though the shebang of script #!/data/data/com.termux/files/usr/bin/bash looks ok, it means that wp command (located at /data/data/com.termux/files/usr/bin/wp) used inside the script contains shebang #!/usr/bin/env wp and should modify it to #!/data/data/com.termux/files/usr/bin/env wp too. termux-exec of first method should fix this specific case too(already has correct shebang in main script).

.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

Running Python script to deploy from MSBuild

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

Running the "exec" command in Jenkins "Execute Shell"

I'm running Jenkins on a Linux host. I'm automating the build of a C++ application. In order to build the application I need to use the 4.7 version of g++ which includes support for c++11. In order to use this version of g++ I run the following command at a command prompt:
exec /usr/bin/scl enable devtoolset-1.1 bash
So I created a "Execute shell" build step and put the following commands, which properly builds the C++ application on the command prompt:
exec /usr/bin/scl enable devtoolset-1.1 bash
libtoolize
autoreconf --force --install
./configure --prefix=/home/tomcat/.jenkins/workspace/project
make
make install
cd procs
./makem.sh /home/tomcat/.jenkins/workspace/project
The problem is that Jenkins will not run any of the commands after the "exec /usr/bin/scl enable devtoolset-1.1 bash" command, but instead just runs the "exec" command, terminates and marks the build as successful.
Any ideas on how I can re-structure the above so that Jenkins will run all the commands?
Thanks!
At the begining of your "Execute shell" script, execute source /opt/rh/devtoolset-1.1/enable to enable the devtoolet "inside" of your shell.
Which gives:
source /opt/rh/devtoolset-1.1/enable
libtoolize
autoreconf --force --install
./configure --prefix=/home/tomcat/.jenkins/workspace/project
make
make install
cd procs
./makem.sh /home/tomcat/.jenkins/workspace/project
I needed to look up what scl actually does.
Examples
scl enable example 'less --version'
runs command 'less --version' in the environment with collection 'example' enabled
scl enable foo bar bash
runs bash instance with foo and bar Software Collections enabled
So what you are doing is running a bash shell. I guess, that the bash shell returns immediately, since you are in non-interactive mode. exec runs the the command within the shell without creating a new shell. That means if the newly opened bash ends it also ends your shell prematurely. I would suggest to put all your build steps into a bash script (e.g. run_my_build.sh) and call it in the following way.
exec /usr/bin/scl enable devtoolset-1.1 run_my_build.sh
This kind of thing normally works in "find" commands, but may work here. Rather than running two, or three processes, you run one "sh" that executes multiple things, like this:
exec sh -c "thing1; thing2; thing3"
If you require each step to succeed before the next step, replace the semi-colons with double ampersands:
exec sh -c "thing1 && thing2 && thing3"
I have no idea which of your steps you wish to run together, so I am hoping you can adapt the concept to fit your needs.
Or you can put the whole lot into a script and exec that.

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>