在使用Git标记时,我使用GitHub存储库中的以下yaml将NuGet包发布到Azure工件和每个提交上的GitHub包以及官方的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时,上面的发布步骤失败了,因为:
GitHubUserName和GitHubPersonalAccessToken。是否有可能安全地运行Azure工件和PR的GitHub发布步骤?特别是,我不希望有人更改azure-pipelines.yml或蛋糕制作 build.cake文件来窃取我的秘密变量或发布他们自己的包。
如果这是不可能的,我想我必须跳过这些步骤从公关。我怎么能做到这一点?
发布于 2019-10-11 07:57:16
如果不可能的话?
恐怕这是不可能做到的。由于用户没有权限,所以秘密变量GitHubUserName和GitHubPersonalAccessToken。这是这个问题的关键,如果你不想泄露你的秘密变量,这是无法回避的。
我想我必须跳过公关的这些步骤。我该怎么做呢?
答案是肯定的。
可以使用表达式计算内置变量Build.Reason,以确定任务是否作为拉请求分支策略的一部分执行构建,如下所示:
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))然后,当构建由PullRequest触发时,这些任务将被跳过。
有关更多细节,请查看文档条件。
希望这能有所帮助。
https://stackoverflow.com/questions/58318057
复制相似问题