nightroman / Invoke-Build

Build Automation in PowerShell

Home Page:https://github.com/nightroman/Invoke-Build/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing the original working directory

brantb opened this issue · comments

I would like to use the current directory to infer the value of an (optional) parameter. The only way I could figure out how to do this was by accessing the "private" ${*} variable like this:

param([string]$WorkDir)

Task Demo {
  # If -WorkDir was not provided, infer it from cwd
  if (-not $WorkDir) {
    $WorkDir = ${*}.CD
  }
  # ... do stuff with $WorkDir
}

Assuming I haven't missed a non-hacky way of getting this, could ${*}.CD be exposed via a built-in variable? Maybe $OriginalLocation?

You are right, ${*}.CD is currently the only way. The request for the official built-in variable looks reasonable. Let me think about this.

v5.8.1 introduces $OriginalLocation.

Hi,
so $BuildRoot variable points to a directory where the scripts is located;
and $OriginalLocation points to my current working directory.

Did I get it right?

Maybe it also could be added to Special Variables?

@GreatTeacherBasshead

so $BuildRoot variable points to a directory where the scripts is located;

Where the current build script is located, unless this variable is changed by the script itself in special (rare) cases.

and $OriginalLocation points to my current working directory.

Yes, your current before and after the build. But during the build the current is $BuildRoot.

Maybe it also could be added to Special Variables?

Thank you, of course! It's done. Also $Job was missing there.

@nightroman Sorry for necroing on this issue, but could this $OriginalLocation be added to the docs?

Let's just say that it took me a significant chunk of time to find it. 😉

Probably, here?

@fdcastel Sure, I'll take care in the place you suggested and think of other suitable. Thank you.

Done at the wiki as you suggested. It is also mentioned in help Invoke-Build, see PUBLIC VARIABLES.