I've got a simple PowerShell script that I'm calling from Jenkins:
function PerformRepoActions($localRepo)
{
  $startDir = $pwd.path
  cd $localRepo
  hg recover
  hg revert --all
  hg pull -r $branch --rebase
  hg update -r $branch
  cd $startDir
}
$branch = $env:NAMEDBRANCH
PerformRepoActions $pwd.path 
When I run this, it does not show any of the mercurial commands that I'm making. Here's what it shows in the Jenkins output:
no interrupted transaction available
pulling from [repo_location]
no changes found
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
It's giving me the the output of the hg commands, but not showing the commands themselves.
So, I'm looking for something that will make those commands print out, equivalent to the cmd.exe "echo on".
A search tells me that the equivalent in PowerShell is "Set-PSDebug -Trace 1". So I add that to the beginning of the script, and it changes the output to:
DEBUG:   15+  >>>> $branch = $env:NAMEDBRANCH
DEBUG:   16+  >>>> PerformRepoActions $pwd.path
DEBUG:    5+  >>>> {
DEBUG:    6+    >>>> $startDir = $pwd.path
DEBUG:    7+    >>>> cd $localRepo
no interrupted transaction available
pulling from ssh://hg@mercurial.wilcoxassoc.com/PcDmis/QA
no changes found
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
As you can see, while it does give me more output, but it doesn't actually show me the commands that I'm calling.
"Set-PSDebug -Trace 2" gives even more output, but still doesn't show what mercurial commands are being called.
The work-around that I've come up with is to create a function which echoes and the executes a string. It works, but it feels awful kludgey:
function execute($cmd)
{
  echo $cmd
  iex $cmd
}
function PerformRepoActions($localRepo)
{
  $startDir = $pwd.path
  execute "cd $localRepo"
  execute "hg recover"
  execute "hg revert --all"
  execute "hg pull -r $branch --rebase"
  execute "hg update -r $branch"
  execute "cd $startDir"
}
$branch = $env:NAMEDBRANCH
PerformRepoActions $pwd.path
Is there some better way to do this?
It seems that there must be, but I've been surprised before.
edit: This is not a duplicate of PowerShell "echo on". Re-directing the output to a file, the answer to that question, isn't feasible. I need it to display in the Jenkins output, not a file.