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

Using task PowershellTask@2 to invoke a pscore script in a YAML pipeline generates a dotnet error #15175

Closed
tristanbarcelon opened this issue Aug 19, 2021 · 4 comments
Assignees
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug Task: PowerShell

Comments

@tristanbarcelon
Copy link

tristanbarcelon commented Aug 19, 2021

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Bug

Enter Task Name: Powershell

list here (V# not needed): 2

Environment

  • Server - Azure Pipelines

    Please reach out to me in private so I can provide account name, team project name, build definition name, and build number.

  • Agent - Hosted:

    I'm using pool with vmImage: 'ubuntu-latest' in yaml pipeline. I've tried using private agents as well and the same error persists .

Issue Description

When calling a powershell script via pwsh, I get an unexpected error about an option: -V which I'm never setting at all in my script or in the YAML task.

- task: PowerShell@2
  displayName: 'Set or register PrivatePSGallery'
  inputs:
    targetType: 'filePath'
    filePath: '$(Build.SourcesDirectory)/src/setprivatepsgallery.ps1'
    arguments: '-RepositoryName $(PowershellRepositoryName) -RepositorySourceLocation $(PowershellRepositorySourceLocation)'
    failOnStderr: true
    showWarnings: true
    pwsh: true
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

Task logs

Please reach out to me privately so I can provide you a zip file of the task logs.

Error logs

##[debug]/usr/bin/pwsh arg: . '/home/vsts/work/_temp/a132de4b-03fd-42f2-bb22-8aecb6d3cd96.ps1'
##[debug]exec tool: /usr/bin/pwsh
##[debug]arguments:
##[debug] -NoLogo
##[debug] -NoProfile
##[debug] -NonInteractive
##[debug] -Command
##[debug] . '/home/vsts/work/_temp/a132de4b-03fd-42f2-bb22-8aecb6d3cd96.ps1'
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/home/vsts/work/_temp/a132de4b-03fd-42f2-bb22-8aecb6d3cd96.ps1'

Id Name PSJobTypeName State HasMoreData Location


1 94558a0b-00d0-… NotStarted False
Searching for repository: PrivatePSGallery
Registering repository PrivatePSGallery name with SourceLocation to https://pkgs.dev.azure.com/myaccount/_packaging/myfeedname/nuget/v2
Unknown option: -V

@max-zaytsev max-zaytsev added Task: PowerShell Area: ABTT Akvelon Build Tasks Team area of work and removed route labels Aug 19, 2021
@tristanbarcelon
Copy link
Author

tristanbarcelon commented Aug 19, 2021

Hi @max-zaytsev , thank you for taking a look at this issue. I've also opened up a ticket (2108190040004024) with azure devops support to see if I can get quicker resolution. I've looked at the yaml pipeline definition and my powershell script but couldn't find anything I'm providing that's a -V. setprivatepsgallery.ps1 is defined below. Am I passing the arguments incorrectly in the YAML pipeline step?

[CmdletBinding()]
param(
    [Parameter(Mandatory = $true, HelpMessage = 'Powershell repository name to set or register')]
    [string] $RepositoryName,
    [Parameter(Mandatory = $true, HelpMessage = 'Azure Devops feed URL to use as repository source')]
    [string] $RepositorySourceLocation
)
begin {}
process {
    try
    {
        [string] $BuildDefinition = $ENV:BUILD_DEFINITIONNAME

        if ([string]::IsNullOrEmpty($ENV:SYSTEM_ACCESSTOKEN))
        {
            Write-Error "Build pipeline: $BuildDefinition needs to have access to SYSTEM_ACCESSTOKEN environment variable"
        }
        else
        {
            $AZDOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @('buildagent', (ConvertTo-SecureString -String $ENV:SYSTEM_ACCESSTOKEN -AsPlainText -Force))
        }

        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13

        Write-Host "Searching for repository: $($RepositoryName)"
        $PrivateRepository = Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue -Verbose:$false

        if ($null -eq $PrivateRepository)
        {
            $PrivateRepository = Get-PSRepository -Verbose:$false | Where-Object { ($_.SourceLocation -ieq $RepositorySourceLocation) -and ($_.Name -ine $RepositoryName) } 
            if ($null -ne $PrivateRepository)
            {
                Write-Host "Unregistering repository $($RepositoryName)"
                Unregister-PSRepository -Name $RepositoryName
            }
            Write-Host "Registering repository $($RepositoryName) name with SourceLocation to $($RepositorySourceLocation)"
            Register-PSRepository -Name $RepositoryName -SourceLocation $RepositorySourceLocation -InstallationPolicy Trusted -Credential $AZDOCredential
        }
        else
        {
            if (($PrivateRepository.SourceLocation -ine $RepositorySourceLocation) -or ($PrivateRepository.InstallationPolicy -ine 'Trusted'))
            {
                Write-Host "Updating repository $($RepositoryName) because its InstallationPolicy and SourceLocation do not match expected values"
                Set-PSRepository -Name $RepositoryName -InstallationPolicy Trusted -SourceLocation $RepositorySourceLocation -Credential $AZDOCredential
            }
            else
            {
                Write-Host "Found repository: $($RepositoryName) and no updates are needed"
            }
        }
    }
    catch {
        throw $_
    }
    finally {
        Get-Variable -Scope local | Remove-Variable -ErrorAction SilentlyContinue
    }
}
end {}

@max-zaytsev
Copy link

Hi @tristanbarcelon It doesn't look like a task issue. Is this reproducible if you run your ps script manually on the same machine?

@max-zaytsev max-zaytsev self-assigned this Sep 19, 2021
@tucsonted66771
Copy link

tucsonted66771 commented Sep 19, 2021 via email

@tristanbarcelon
Copy link
Author

Hi @max-zaytsev, looks like powershell team confirmed this as an issue with PowershellGet so it's not an issue with powershell task.

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

3 participants