Skip to content
Open
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
24 changes: 16 additions & 8 deletions Tasks/AzurePowerShellV5/RemoveAzContext.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Import-Module "$PSScriptRoot\ps_modules\VstsTaskSdk" -ArgumentList @{ NonInteractive = $true }

. "$PSScriptRoot/Utility.ps1"
. "$PSScriptRoot/ps_modules/VstsAzureHelpers_/Utility.ps1"
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
try {
. "$PSScriptRoot/Utility.ps1"
. "$PSScriptRoot/ps_modules/VstsAzureHelpers_/Utility.ps1"

Update-PSModulePathForHostedAgentLinux
Disconnect-AzureAndClearContext -restrictContext 'True'
Update-PSModulePathForHostedAgentLinux
Disconnect-AzureAndClearContext -restrictContext 'True'

if ($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ""
$env:AZURESUBSCRIPTION_CLIENT_ID = ""
$env:AZURESUBSCRIPTION_TENANT_ID = ""
if ($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ""
$env:AZURESUBSCRIPTION_CLIENT_ID = ""
$env:AZURESUBSCRIPTION_TENANT_ID = ""
}
}
catch {
Write-Host "##vso[task.logissue type=error]$($_.Exception.Message)"
exit 1
}
8 changes: 7 additions & 1 deletion Tasks/AzurePowerShellV5/azurepowershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ async function run() {
tl.setResult(tl.TaskResult.Failed, err.message || 'run() failed');
}
finally {
let cleanupExitCode = 0;
try {
const powershell = tl.tool(tl.which('pwsh') || tl.which('powershell') || tl.which('pwsh', true))
.arg('-NoLogo')
Expand All @@ -197,10 +198,15 @@ async function run() {
outStream: process.stdout, // of order since Node buffers it's own STDOUT but not STDERR.
ignoreReturnCode: true
};
await powershell.exec(options);
cleanupExitCode = await powershell.exec(options);
tl.debug(`Cleanup exit code: ${cleanupExitCode}`);
}
catch (err) {
tl.debug("Az-clearContext not completed due to an error");
tl.setResult(tl.TaskResult.Failed, err.message);
}
if (cleanupExitCode !== 0) {
tl.setResult(tl.TaskResult.Failed, `Cleanup failed with exit code ${cleanupExitCode}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 5,
"Minor": 264,
"Patch": 0
"Patch": 1
},
"releaseNotes": "Added support for Az Module and cross platform agents.",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV5/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 5,
"Minor": 264,
"Patch": 0
"Patch": 1
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"groups": [
Expand Down