【发布时间】:2019-10-10 07:57:49
【问题描述】:
我在GitHub repository 中使用以下 yaml 将 NuGet 包发布到 Azure Artifacts 和 GitHub 包,并在我使用 Git 标记时发布到官方 NuGet 存储库。
- stage: Deploy
jobs:
- deployment: AzureArtefacts
displayName: 'Azure Artefacts'
pool:
vmImage: windows-latest
environment: 'Azure Artefacts'
strategy:
runOnce:
deploy:
steps:
- task: NuGetToolInstaller@1
displayName: 'NuGet Install'
- task: NuGetAuthenticate@0
displayName: 'NuGet Authenticate'
- script: nuget push $(Agent.BuildDirectory)\Windows\*.nupkg -Source https://pkgs.dev.azure.com/serilog-exceptions/_packaging/serilog-exceptions/nuget/v3/index.json -ApiKey AzureArtifacts -SkipDuplicate
displayName: 'NuGet Push'
failOnStderr: true
- deployment: GitHub
pool:
vmImage: windows-latest
environment: 'GitHub'
strategy:
runOnce:
deploy:
steps:
- task: NuGetToolInstaller@1
displayName: 'NuGet Install'
- script: nuget source Add -Name GitHub -Source https://nuget.pkg.github.com/RehanSaeed/index.json -UserName $(GitHubUserName) -Password $(GitHubPersonalAccessToken)
displayName: 'NuGet Add Source'
failOnStderr: true
- script: nuget push $(Agent.BuildDirectory)\Windows\*.nupkg -Source GitHub -SkipDuplicate
displayName: 'NuGet Push'
failOnStderr: true
- deployment: NuGet
pool:
vmImage: windows-latest
environment: 'NuGet'
condition: startsWith(variables['Build.sourceBranch'], 'refs/tags/')
strategy:
runOnce:
deploy:
steps:
- task: NuGetToolInstaller@1
displayName: 'Install NuGet'
- script: nuget push $(Agent.BuildDirectory)\Windows\*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey $(NuGetApiKey) -SkipDuplicate
displayName: 'NuGet Push'
failOnStderr: true
当我签入时这工作正常,但是当有人创建 PR 时,上述发布步骤失败,因为:
- Azure Artifacts - 用户没有权限。
- GitHub - 用户无权使用秘密变量
GitHubUserName和GitHubPersonalAccessToken。 - NuGet - 构建未从 Git 标记运行,因此此步骤不会运行。
是否可以从 PR 安全地运行 Azure Artifacts 和 GitHub 发布步骤?特别是,我不希望有人更改 azure-pipelines.yml 或我的 Cake build build.cake 文件来窃取我的秘密变量或发布他们自己的包。
如果这不可能,我想我必须从 PR 中跳过这些步骤。我该怎么做?
【问题讨论】:
-
我的第一个想法是您需要两个构建定义。两者都可以指向同一个 yaml/cake 脚本,但 PR 构建不应定义任何秘密,而另一个构建应仅在更改锁定分支或新标签时触发。如果你重复使用相同的 yaml,那么你需要条件来跳过未定义秘密值的步骤。
-
@Muhammad Rehan Saeed,为什么没有标记?我可以知道它的原因吗?如果您需要进一步的帮助,请告诉我们。
-
我希望有一天有人可以提供一种可以部署 PR 的解决方案。也许那是不现实的,请回击。
标签: github nuget pull-request azure-artifacts github-package-registry