简体   繁体   English

为 GitHub 版本重用 Azure DevOps 管道

[英]Reuse Azure DevOps pipeline for GitHub release

I already have an existing Azure DevOps pipeline .我已经有一个现有的Azure DevOps pipeline It gets triggered whenever a new commit is pushed to the corresponding GitHub repo and does all the ceremony ( build , test , etc.).每当新的提交被推送到相应的GitHub库并执行所有仪式(构建测试等)时,它就会被触发。

Now I want to setup the release.现在我想设置发布。 A release has to happen whenever a pushed commit is tagged with release-v* .每当推送的提交被标记为release-v*时,就必须进行发布。 This should execute the same ceremony as already specified, but finally does a GitHub release.这应该执行与已经指定的相同的仪式,但最终会发布 GitHub。

What is the best way to accomplish this?实现这一目标的最佳方法是什么? Do I need to duplicate my pipeline?我需要复制我的管道吗? Can I reuse it?我可以重复使用它吗?

I finally ended up with the following build configuration:我最终得到了以下构建配置:

trigger:
- master
- release

# All the other YAML stuff

- task: PublishGitHubRelease@0
  inputs:
    applicationName: 'TheApplication'
    gitSourceOption: 'github'
    token: '$(GitHubPAT)'
    repo: 'TheRepository'
    owner: 'TheOwner'
    tagName: 'v$(build.buildNumber)'
    releaseName: 'v$(build.buildNumber)'
    draft: false
    prerelease: false
    assetsPattern: '$(Build.SourcesDirectory)/*'
  displayName: 'Create GitHub release'
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/release'))

Now I'm having two different branches: master and release .现在我有两个不同的分支: masterrelease The build configuration gets triggered for both branches, but the final task PublishGitHubRelease will only be executed for the release branch.两个分支都会触发构建配置,但最终任务PublishGitHubRelease只会为release分支执行。 The very last line condition: is responsible for that.最后一行condition:负责。 For a release, I'm doing a fast-forward merge from master to release .对于发布,我正在做一个从masterrelease的快进合并。

It's not my favorite solution, but it's okay for now.这不是我最喜欢的解决方案,但现在还可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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