Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: AzureCLI@2 failOnStandardError does not fail with stderr on Windows #20291

Open
4 of 7 tasks
WangWeiLin-MV opened this issue Aug 14, 2024 · 0 comments
Open
4 of 7 tasks

Comments

@WangWeiLin-MV
Copy link

WangWeiLin-MV commented Aug 14, 2024

New issue checklist

Task name

AzureCLI

Task version

2

Issue Description

On Windows, it seems that task AzureCLI@2 does not fail with ::WriteFile stderr output, while PowerShell@2 fails as expected. I tried std::cerr before but did not reproduce.

Repro result see https://dev.azure.com/vcpkg/public/_build/results?buildId=106047, which all four tasks run the same program, two of them redirecting stderr to null for comparison.

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

windows-latest

Relevant log output

AzureCLI@2:

"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\********.ps1'"
stdout
stderr
C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" account clear"
Finishing: AzureCLI

---

PowerShell@2:

"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\********.ps1'"
stdout
##[error]stderr
Finishing: PowerShell

Full task logs with system.debug enabled

 [REPLACE THIS WITH YOUR INFORMATION] 

Repro steps

pool:
  vmImage: "windows-latest"
jobs:
  - job: buildTest
    displayName: "Build test.exe"
    steps:
      - checkout: none
      - task: PowerShell@2
        displayName: "build"
        inputs:
          pwsh: true
          targetType: inline
          script: |
            @'
            #include <windows.h>
            #include <iostream>
            int main() {
                std::cout << "stdout" << std::endl;
                HANDLE hStderr = ::GetStdHandle(STD_ERROR_HANDLE);
                if (hStderr == INVALID_HANDLE_VALUE) {
                  return 1;
                }
                DWORD written = 0;
                const char* msg = "stderr\n";
                if (!::WriteFile(hStderr, msg, strlen(msg), &written, nullptr)) {
                    return 1;
                }
                return 0;
            }
            '@ > test.cxx
            $dir = $PWD
            & "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
            cd $dir
            cl /nologo /std:c++20 /EHsc /Fe:test.exe test.cxx
          failOnStderr: true
      - publish: "test.exe"
        artifact: test_bin
  - job: test1
    dependsOn: buildTest
    displayName: Run stderr PowerShell@2
    steps:
      - checkout: none
      - download: current
        artifact: test_bin
      - task: PowerShell@2
        inputs:
          pwsh: true
          targetType: inline
          script: |
            & $(Pipeline.Workspace)/test_bin/test.exe
          failOnStderr: true
  - job: test2
    dependsOn: buildTest
    displayName: Run stderr PowerShell@2 redirect stderr to null
    steps:
      - checkout: none
      - download: current
        artifact: test_bin
      - task: PowerShell@2
        inputs:
          pwsh: true
          targetType: inline
          script: |
            & $(Pipeline.Workspace)/test_bin/test.exe 2>$null
          failOnStderr: true
  - job: test3
    dependsOn: buildTest
    displayName: Run stderr AzureCLI@2
    steps:
      - checkout: none
      - download: current
        artifact: test_bin
      - task: AzureCLI@2
        inputs:
          azureSubscription: "********"
          scriptType: "pscore"
          scriptLocation: "inlineScript"
          inlineScript: |
            & $(Pipeline.Workspace)/test_bin/test.exe
          failOnStandardError: true
  - job: test4
    dependsOn: buildTest
    displayName: Run stderr AzureCLI@2 redirect stderr to null
    steps:
      - checkout: none
      - download: current
        artifact: test_bin
      - task: AzureCLI@2
        inputs:
          azureSubscription: "********"
          scriptType: "pscore"
          scriptLocation: "inlineScript"
          inlineScript: |
            & $(Pipeline.Workspace)/test_bin/test.exe 2>$null
          failOnStandardError: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant