简体   繁体   中英

Artifactory restore nuget packages with authentication from powershell

Our team started using Artifactory a few weeks ago and one of the challenges we are currently trying to work through is authentication. Currently we have every developer setup in Artifactory with an account login, we have a build.ps1 file that we use to restore our nuget packages but we're trying to automate this process.

Here is what our powershell script looks like. But it is not prompting the user to enter their username and password, unless they add it as parameters to the .\\build.ps1 command line but the issue there is that the password is being entered in plain text.

"Updating NuGet Dependencies"
$nuget = "$rootDir\.nuget\NuGet.exe"
if ($nuser)
{
    Invoke-Expression "$nuget Sources Update -Name 'Artifactory' -UserName $user -Password $pass"
}
Invoke-Expression "$nuget install -NonInteractive -DisableParallel"
if ($lastexitcode -ne 0) {
    Write-Host -foreground red "Error occurred downloading dependencies."
    exit 1
}
dir . | where { $_.psiscontainer } | where { (test-path (join-path $_.fullname "packages.config")) } | foreach {
    Invoke-Expression "$nuget install '$($_.fullname)\packages.config' -NonInteractive -DisableParallel"
    if ($lastexitcode -ne 0) {
        Write-Host -foreground red "Error occurred downloading project dependencies."
        exit 1
    }
}

This article on handling passwords and credentials might prove useful to you:

Working with Passwords, Secure Strings and Credentials in Windows PowerShell

I had some problems with setting the credentials.

My solutions was to upgrade nuget.exe (v4.3.0 from v3.xx) and using the Add Sources with the username/ password, with the ApiKey from the Artifactory as the password.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM