Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ protected override void BeginProcessing()
ThrowTerminatingError(errorRecord);
Comment thread
SteveL-MSFT marked this conversation as resolved.
Resolved
Comment thread
SteveL-MSFT marked this conversation as resolved.
Resolved
}

if (WorkingDirectory == null)
{
try
{
WorkingDirectory = SessionState.Internal.CurrentLocation.Path;
}
catch (PSInvalidOperationException)
{
}
}

CommandDiscovery.AutoloadModulesWithJobSourceAdapters(this.Context, this.CommandOrigin);

if (ParameterSetName == DefinitionNameParameterSet)
Expand Down
8 changes: 8 additions & 0 deletions test/powershell/engine/Job/Jobs.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe 'Basic Job Tests' -Tags 'CI' {
BeforeAll {
# Make sure we do not have any jobs running
Expand Down Expand Up @@ -89,6 +90,13 @@ Describe 'Basic Job Tests' -Tags 'CI' {
{Start-Job -ScriptBlock { 1 + 1 } -WorkingDirectory $path} | Should -Throw -ErrorId $expectedErrorId
}

It 'Verifies that the current working directory is preserved' {
$job = Start-Job -ScriptBlock { $pwd }
$location = $job | Wait-Job | Receive-Job
$job | Remove-Job
$location.Path | Should -BeExactly $pwd.Path
}

It "Create job with native command" {
try {
$nativeJob = Start-job { pwsh -c 1+1 }
Expand Down