In the above examples, HOME is assumed to defined on the agent (via .bash_profile etc). But the above examples are also valid for environment variables defined via Go (built-in or otherwise). So, for example:
Finally, let’s consider cases where quoting is needed. Suppose you need to send an email from the command-line. You might do something like this:
Without the double quotes, the subject part of that mail could not have more than one word. Single-quotes could replace double-quotes here. Most times, you’ll need single-quotes when you need to nest quotes.
Say you need to send that email from a remote box (maybe only it has SMTP settings set properly). You could do something like this:
<arg>ssh remotehost 'echo hello there | mail -s "subject line" firstname.lastname@example.org'</arg>
You need the single quotes here so that the whole “echo … | mail …” part is sent to the remote host.
Go considers the task as successful if the custom command exits with zero, else the task (and it's job) are failed. Some windows commands don't follow this convention. Given robocopy's behaviour, the following task fails even if robocopy doesn't.
rundll32 without any arguments is effectively a no-op. This sets the overall errorlevel to zero. Of course, this means the task won't fail even if there is a genuine robocopy failure so use with care.
In case of Powershell script-blocks, the exit code is non-zero if any of the cmdlets in the script block writes to the error-stream. Writing status to error stream is common practice for utils like curl and git. To handle this in powershell V2, we manually clear the $error variable in the following command that executes a git pull remotely using powershell and winrm. V3 claims to have -ErrorAction:Ignore option for this.
Prefer version controlled scripts over fully inline commands
The above powershell hack is a limited workaround to make it work as a fully inline custom command. Fully inline commands are useful to quickly iterate and get the command working. It is better to move long complicated commands into version controlled script files (make them part of the material for the pipeline) and simply run the script from inside a Go custom command.
Thanks to Arvind and Sachin for their inputs to this article.