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

PowerShellV2 ErrorActionPreference #16048

Closed
awdavies90 opened this issue Mar 18, 2022 · 5 comments
Closed

PowerShellV2 ErrorActionPreference #16048

awdavies90 opened this issue Mar 18, 2022 · 5 comments
Assignees
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug Task: PowerShell

Comments

@awdavies90
Copy link

Question, Bug, or Feature?
Type: Bug

Enter Task Name: PowerShellV2

Environment

  • Server - Azure Devops Server
    • Version: Version 17.143.28621.4

Issue Description

The PowerShellV2 task has an option for setting the ErrorActionPreference of a script. This is great but I've noticed that the task adds the $ErrorActionPreference = '{selectedOption}' at the beginning of your chosen script or inline script, regardless of whether the script already contains a line where the $ErrorActionPreference is set.

If the $ErrorActionPreference is explicitly being set in a script then it should be honoured and the PSV2 task should not prefix the script itself.

I've also noticed that if a script contains a param block and is used inline, the error action preference line is added above the param block which causes the script to fail. With this in mind it would be good to either have the option to not specify an ErrorActionPreference within the task or for the preference line to only be added if the script does not contain one already.

P.S. I'm aware that if the above change(s) are made, as I'm currently using on-prem AzDO I'll still have the problem. That's fine, I just wanted to bring it to your attention.

@mr-dokara
Copy link
Contributor

Hello @awdavies90, I've investigated your issue. You can set ErrorActionPreference as Default in the task settings and this line will not be added to the ps script.

@awdavies90
Copy link
Author

image
Is this something that can only be done through yaml? There's doesn't seem to be an option for it in the classic view (E.g. A task group).

@mr-dokara
Copy link
Contributor

Most likely, your version of Azure DevOps Server doesn't include the fix for this task. I think in future versions of the ADO server this feature will be added. Related PR with the fix: #15069

@DenisRumyantsev DenisRumyantsev self-assigned this Apr 6, 2022
@anatolybolshakov
Copy link
Contributor

Hi @awdavies90 please ping if you have any questions. You can probably build task by yourself and upload it via tfx-cli to your local server, although this is not supported. These task changes will be released with one of the next releases of on-prem server.

@DenisRumyantsev
Copy link
Contributor

Hi @awdavies90, let me close this issue for now. Feel free to reopen it if you have any additional questions about the PowerShell task. For now, you can upload it to your local server via tfx-cli, as was mentioned

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 bug Task: PowerShell
Projects
None yet
Development

No branches or pull requests

4 participants