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

PowerShell task should configure logging streams #15069

Conversation

bradselw
Copy link
Member

@bradselw bradselw commented Jul 22, 2021

Task name: PowerShellV2

Description: PowerShell has several output streams, many of which are used for logging. PowerShell supports different actions when objects are written to each of these streams, such as stopping execution, printing a message, or ignoring it. For example, the Stop action tells PowerShell to display a message and stop execution.

While actions can be specified in scripts, a more common pattern is for the caller to specify the preferred "verbosity" of the script by setting the corresponding "preference" variable to a default action, to be used in cases where one is not already provided. For example, the PowerShellV2 task does this with the error stream: It allows the user to select what action they want to be taken (i.e. Stop, Continue, or SilentlyContinue) when an object is written to the error stream, by setting the $ErrorActionPreference variable at the beginning of the script.

Unfortunately, the PowerShellV2 task currently only gives users control over the error stream. All other streams are handled by PowerShell's default settings, which are rather limited and not suited for automation. Specifically, by default PowerShell suppresses the information and verbose streams, both of which provide crucial logging. The information stream is "intended to provide messages that help a user understand what a script is doing", while the verbose stream is "intended for messages that help users troubleshoot commands as they are run ... from a script." The PowerShellV2 task is meant to run on an agent in an automated environment that the user has limited access to, which makes the logging provided by these streams all the more vital.

This pull request addresses this gap in the PowerShellV2 task's logging in the follow ways:

  1. It configures the information stream to log all messages by default
  2. It configures the verbose stream to log all messages on an opt-in basis
    • Specifically, the verbose stream will log messages when the pipeline's System.Debug variable is set to true. This is an established pattern leveraged across other tasks.
  3. It explicitly defines the action to be taken for the warning stream
    • Hard-coded to always print warnings, instead of relying on PowerShell's defaults

Documentation changes required: No.

Added unit tests: Yes, updated existing unit tests.

Attached related issue: Yes: #15053

Checklist:

  • Task version was bumped - please check instruction how to do it
  • Checked that applied changes work as expected

@bradselw bradselw requested a review from mjroghelia as a code owner July 22, 2021 00:04
@mjroghelia mjroghelia added the Area: ABTT Akvelon Build Tasks Team area of work label Jul 22, 2021
@mjroghelia mjroghelia requested a review from a team July 22, 2021 19:01
Copy link
Contributor

@mjroghelia mjroghelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, but I'll leave it to @anatolybolshakov for the final approval.

@EzzhevNikita
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@bradselw
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 15069 in repo microsoft/azure-pipelines-tasks

@bradselw
Copy link
Member Author

@EzzhevNikita I pushed a fix for the failing tests. Would you mind kicking off another run?

@EzzhevNikita
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@alexander-smolyakov alexander-smolyakov self-assigned this Aug 2, 2021
Copy link
Contributor

@anatolybolshakov anatolybolshakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for contribution!
Could you please take a look at the quick comment above?

@anatolybolshakov anatolybolshakov requested a review from a team August 2, 2021 15:40
@bradselw
Copy link
Member Author

bradselw commented Aug 4, 2021

@anatolybolshakov I have updated the task version number as requested, thanks for the feedback! Who else needs to sign off before we can merge?

@alexander-smolyakov
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

Copy link
Contributor

@alexander-smolyakov alexander-smolyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and please take a look at the comment.

Also tested these changes manually, found no issues.
Link to the related test pipeline: https://v-alsmo.visualstudio.com/Test%20Playground/_build/results?buildId=1316&view=results

Tasks/PowerShellV2/powershell.ps1 Outdated Show resolved Hide resolved
@bradselw
Copy link
Member Author

Sorry about the delay. I had to focus on another project for the past month.

@anatolybolshakov I have made the requested changes. @alexander-smolyakov could we kick off another /azp run?

@alexander-smolyakov
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@alexander-smolyakov
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

Copy link
Contributor

@anatolybolshakov anatolybolshakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!
Tested it locally with different preference values - works fine for me also.

@anatolybolshakov
Copy link
Contributor

@bradselw just one final comment - could you please bump task version to 2.194.0 - since for 193 sprint tasks are already shipped to be rolled out?

Copy link
Contributor

@alexander-smolyakov alexander-smolyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@bradselw
Copy link
Member Author

@anatolybolshakov done. What are the next steps for getting this rolled out?

@bradselw
Copy link
Member Author

PR to update the docs: MicrosoftDocs/azure-devops-docs#11207

@anatolybolshakov, @alexander-smolyakov what are the next steps here?

@anatolybolshakov
Copy link
Contributor

@bradselw thanks! We are proceeding with merging at the moment

@anatolybolshakov
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@anatolybolshakov anatolybolshakov merged commit cfceb4c into microsoft:master Sep 21, 2021
@bradselw
Copy link
Member Author

Thanks @anatolybolshakov. When will this become available broadly? I am trying to decide when to merge the changes to the docs.

@anatolybolshakov anatolybolshakov added awaiting deployment Related changes are waiting for deployment to be completed and removed awaiting deployment Related changes are waiting for deployment to be completed labels Sep 23, 2021
@anatolybolshakov
Copy link
Contributor

@bradselw it will be rolled out during 195 sprint - per calendar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ABTT Akvelon Build Tasks Team area of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants