简体   繁体   English

Azure 管道 - 在不提交存储库的情况下发布 Maven 工件

[英]Azure Pipeline - Publish Maven Artifacts Without Comitting to Repository

New to Azure in general so sorry if my question isn't as concise as it should be.总的来说,Azure 是新手,如果我的问题不够简洁,我深表歉意。

What I'm trying to do: When someone pushes to master I want the pipeline to bump the project version and release it as an artifact that is available in the Artifacts tab.我正在尝试做的事情:当有人推动 master 时,我希望管道能够提升项目版本并将其作为“工件”选项卡中可用的工件发布。 This shouldn't create any additional commits.这不应该创建任何额外的提交。

What I've tried: To verify that my local connection to Artifacts was working I tried mvn deploy which worked fine but it doesn't handle version bumping automatically, so instead I tried switching over to我尝试了什么:为了验证我与 Artifacts 的本地连接是否正常工作,我尝试了mvn deploy ,它运行良好,但它不会自动处理版本冲突,所以我尝试切换到

mvn -B release:prepare release:perform

As it does take care of bumping but this creates other issues as it commits two additional times to git instead of amending itself onto the head and I need to tinker with soft resets and force push to get it correct.因为它确实处理了碰撞,但这会产生其他问题,因为它会额外提交两次 git 而不是将自己修改到头部,我需要修补软重置并强制推送以使其正确。 Also not sure if it does release to Artifacts as I had issues getting git credentials working...也不确定它是否会发布到 Artifacts,因为我在获取 git 凭据时遇到问题......

Is there a way for the pipeline to look at what Artifacts has already been released and just bump based on that so it doesn't have to commit anything to the repository?有没有一种方法可以让管道查看已经发布的工件并根据它进行碰撞,这样它就不必向存储库提交任何内容?

The Azure Artifacts which's on the left-hand menu is designed to be consumed as shared modules, which is for custom packages instead of publish build artifacts.左侧菜单中的 Azure Artifacts 旨在作为共享模块使用,用于自定义包而不是发布构建工件。 For the Build artifacts, you might check specific pipeline(which finished run) → "Summary" → "Related", and you can see what pipeline published.对于 Build artifacts,您可以检查特定的管道(已完成运行)→“Summary”→“Related”,然后您可以看到发布了哪些管道。

I don't know if I misunderstand your question, and this link might help you get some idea.我不知道我是否误解了您的问题,此链接可能会帮助您了解一些想法。

Okay, so after a lot of days I finally got it workig.好的,所以经过很多天我终于让它工作了。 Releasing artifacts without committing code to repo using organization feeds使用组织提要发布工件而不将代码提交到 repo

trigger:
  - main

pr: none

pool:
  vmImage: ubuntu-latest

variables:
  - name: artifactVersion
  - name: organization
    value: '<organization>'
  - name: feedName
    value: '<feedName>'

steps:
  - task: PowerShell@2
    displayName: Fetching latest version of artifact
    inputs:
      targetType: 'inline'
      script: |
        
        # Get list over packages
        $url = 'https://feeds.dev.azure.com/$(organization)/_apis/packaging/Feeds/$(feedName)/packages?api-version=6.0-preview.1'
        $pipeline = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}

        # Find our artifact in the feed over all artifacts
        $packageName = echo '${project.groupId}:${project.artifactId}' | mvn -N -q -DforceStdout help:evaluate
        echo "Looking for artifact versions for packageName: $packageName"
        $packageId = ''
        Foreach ($package IN $pipeline.value) {
          if($package.name -eq $packageName) {
            $packageId = $package.id
          }
        }
        if($packageId -eq '') {
          echo "No artifact found, assuming this is first release"
          $artifactVersion = 1
        } else {
          $url = 'https://feeds.dev.azure.com/$(organization)/_apis/packaging/Feeds/$(feedName)/Packages/' + $packageId + '/versions?api-version=6.0-preview.1'
          $pipeline = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
        
          # Find latest version of the artifact
          Foreach ($package IN $pipeline.value) {
            if($package.isLatest) {
              $artifactVersion = [int]$package.version+1
            }
          }
        }
        Write-Host "##vso[task.setvariable variable=artifactVersion]$artifactVersion"
        echo "Preparing release for artifaction version: $artifactVersion"
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  - task: MavenAuthenticate@0
    inputs:
      artifactsFeeds: '$(feedName)'
  - task: PowerShell@2
    displayName: Preparing artifact
    inputs:
      targetType: 'inline'
      script: |

        echo "Artifact version to be released: $(artifactVersion)"
        $userNameOfHead = git log -1 --pretty=format:'%an'
        $userEmailOfHead = git log -1 --pretty=format:'%ae'
        git config --global user.email "$userNameOfHead"
        git config --global user.name "$userEmailOfHead"

        mvn -B -DreleaseVersion="$(artifactVersion)" release:prepare release:perform

pom.xml changes needed: pom.xml 需要更改:

...
<plugin>
   <groupId>org.apache.maven.plugins</groupId>                
   <artifactId>maven-release-plugin</artifactId>
   <version>2.5.3</version>
   <configuration>
      <pushChanges>false</pushChanges>
      <localCheckout>true</localCheckout>
   </configuration>
</plugin>
...
<distributionManagement>
   <repository>
      <id><id></id>
      <url>https://pkgs.dev.azure.com/<organization>/_packaging/<feedName>/maven/v1</url>
   </repository>
</distributionManagement>

<scm>
   <developerConnection>
      scm:git:git@github.com:<repo>
   </developerConnection>
</scm>
...

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

相关问题 在 BitBucket 管道中从私有 maven 存储库下载工件 - Stuck download of artifacts from private maven repository in BitBucket pipeline 如何将 Gradle 项目发布到 Azure 工件? - How to publish Gradle project to Azure Artifacts? Azure Devops 管道下载文件共享工件任务 - Azure Devops Pipeline Download Fileshare Artifacts Task Azure 管道 npm 发布未按预期工作 - Azure pipeline for npm publish does not work as expected 如何将 package 从 Visual Studio 发布到 azure 工件 - How to publish a package from Visual Studio to azure artifacts 如何从管道 Azure Devops 访问私有存储库? - How to access a private repository from a pipeline Azure Devops? 如何修改 azure 管道中测试结果的存储库/存储位置 - How to modify the repository / storage location for Test Results in azure pipeline Azure DevOps 同一个发布管道中的多个工件如何防止下载所有工件只有一个有新发布版本的工件 - Azure DevOps multi artifacts in the same release pipeline how to Prevent downloading all artifacts just the one who have a new release version 在发布管道中执行阶段时触发不同的存储库 - Azure DevOps - Trigger different repository when execute stage in a release pipeline - Azure DevOps 将 Synapse 工件发布到工作区 - 状态 - Publish Synapse Artifacts to Workspace - Status
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM