【发布时间】:2021-02-04 20:03:21
【问题描述】:
我已经构建了一个同时使用 PSGallery 和 Azure Devops 的模块(我有一个免费的 repo,我一直在使用它)。这是模块:https://www.powershellgallery.com/packages/xanderu.helpers/0.1.9
我遇到的问题是,当我尝试利用安全存储库时,我不断收到禁止错误。这是我调用模块的方式:
Publish-ToPSGallery -PSGalleryKey $PSGalleryKey `
-secureRepoName 'PowershellAZDO' `
-secureRepopublishApiKey $PATToken `
-secureRepopublishApiURL "https://pkgs.dev.azure.com/$orgName/$projectName/_packaging/$feedName/nuget/v2/" `
-secureRepoUser $secureRepoUser `
-secureRepoPass $PATToken `
-codePath .
它是一个非常严格的模块,但基本上是创建一个具有“私有”标签的模块(或脚本),它应该相应地发布到 PSGallery 或 AZDO。我确定这与我使用令牌和凭据(或 API 密钥)的方式有关。有谁知道我在这里做错了什么?
编辑:作为 xanderu.helpers 的一部分,有一个函数 new-powershelltemplate ,它将自动构建可用于发布管道的模块清单或脚本基线
附加编辑: 我还尝试了以下方法来推送到 myget nuget,它会推送但它不会使用 find-module -repository myget 找到模块:
Publish-ToPSGallery -PSGalleryKey $PSGalleryKey `
-secureRepoName 'MyGet' `
-secureRepopublishApiKey $nugetAPIKey `
-secureRepopublishApiURL "https://www.myget.org/F/$feedName/api/v2" `
-secureRepoUser $secureRepoUser `
-secureRepoPass $secureRepoPass `
-codePath .
编辑 #3 当我跑的时候,我做了更多的乱七八糟的事情
nuget.exe sources
运行脚本后,我可以看到 nuget 将 PowershellAZDO 作为源。然后我运行:
nuget push -Source "PowershellAZDO" -ApiKey AzureDevOps .\xanderu.helpers.0.1.9.nupkg
然后我被提示输入用户名和密码。当我输入用户名和 PATToken 时,它会推送包。这似乎是 Publish-Module 命令中的一个错误,但我不确定为什么。就像模块通过的 PSCredential 不被兑现一样。我不断挖掘,发现在PowerShellGet v2.2.5 PSModule.psm1文件中,有一个调用(第10990行):
Publish-PSArtifactUtility @PublishPSArtifactUtility_Params
实际上我确实在其中看到了 PSCredential 对象。我在 PowerShellGet 模块中添加了以下步骤,似乎可以解决这个问题......但这是它会出现的源代码中的一个错误(从第 6018 行开始):
elseif ($NuGetExePath) {
& $NuGetExePath sources update -Name $Repository -UserName $Credential.Username -Password $Credential.GetNetworkCredential().Password
Publish-NugetPackage -NupkgPath $NupkgFullName -Destination $Destination -NugetApiKey $NugetApiKey -NugetExePath $NuGetExePath -Verbose:$VerbosePreference
}
NuGet 版本:5.7.0.6726
PowerShell获取版本:2.2.5
【问题讨论】:
标签: powershell azure-devops publishing