首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何安全地从蔚蓝制品中的PR中发布到NuGet

如何安全地从蔚蓝制品中的PR中发布到NuGet
EN

Stack Overflow用户
提问于 2019-10-10 07:57:49
回答 1查看 137关注 0票数 0

在使用Git标记时,我使用GitHub存储库中的以下yaml将NuGet包发布到Azure工件和每个提交上的GitHub包以及官方的NuGet存储库。

代码语言:javascript
复制
- 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工件-用户没有权限。
  • GitHub -用户无权使用秘密变量GitHubUserNameGitHubPersonalAccessToken
  • NuGet -构建不是从Git标记上运行的,所以这个步骤不运行。

是否有可能安全地运行Azure工件和PR的GitHub发布步骤?特别是,我不希望有人更改azure-pipelines.yml蛋糕制作 build.cake文件来窃取我的秘密变量或发布他们自己的包。

如果这是不可能的,我想我必须跳过这些步骤从公关。我怎么能做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-11 07:57:16

如果不可能的话?

恐怕这是不可能做到的。由于用户没有权限,所以秘密变量GitHubUserNameGitHubPersonalAccessToken。这是这个问题的关键,如果你不想泄露你的秘密变量,这是无法回避的。

我想我必须跳过公关的这些步骤。我该怎么做呢?

答案是肯定的。

可以使用表达式计算内置变量Build.Reason,以确定任务是否作为拉请求分支策略的一部分执行构建,如下所示:

代码语言:javascript
复制
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))

然后,当构建由PullRequest触发时,这些任务将被跳过。

有关更多细节,请查看文档条件

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58318057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档