运行特定扩展中的Azure Pipelines任务。

huangapple go评论60阅读模式
英文:

Run Azure Pipelines task from specific extension

问题

I'm working on an Azure DevOps extension with a pipeline task. Currently I've published a public "official" version (ID: pr-commentator) of the extension and a private version (ID: pr-commentator-dev) for testing. I want to have both versions installed on my test ADO project to be able to test them, however, I'm struggling to figure out how to distinguish the tasks from each when setting up a pipline, as I seem to only be able to reference the non-unique name of the task:

# azure-pipelines.yaml

steps:
- task: PrCommentator@0 # Same name in both extensions
  inputs:
   # ...

The extension IDs and IDs for the tasks in each extension are all unique as required, but the task names are the same. Since there's no requirement for the name to be unique I'd assume there was a way to reference the one from the specific extension, but I can't figure out how.

I tried things like - task: pr-commentator-dev:PrCommentator@0 and - task: pr-commentator-dev@PrCommentator@0, but the YAML editor doesn't seem to recognize that.

Is this simply not achievable (which means extensions can actually be incompatible)? I'm trying to simplify my extension publish workflow, but I'm wondering if I need to maintain different task names too.

英文:

I'm working on an Azure DevOps extension with a pipeline task. Currently I've published a public "official" version (ID: pr-commentator) of the extension and a private version (ID: pr-commentator-dev) for testing. I want to have both versions installed on my test ADO project to be able to test them, however, I'm struggling to figure out how to distinguish the tasks from each when setting up a pipline, as I seem to only be able to reference the non-unique name of the task:

# azure-pipelines.yaml

steps:
- task: PrCommentator@0 # Same name in both extensions
  inputs:
   # ...

The extension IDs and IDs for the tasks in each extension are all unique as required, but the task names are the same. Since there's no requirement for the name to be unique I'd assume there was a way to reference the one from the specific extension, but I can't figure out how.

I tried things like - task: pr-commentator-dev:PrCommentator@0 and - task: pr-commentator-dev@PrCommentator@0, but the YAML editor doesn't seem to recognize that.

Is this simply not achievable (which means extensions can actually be incompatible)? I'm trying to simplify my extension publish workflow, but I'm wondering if I need to maintain different task names too.

答案1

得分: 1

此文章的文档中,原来我错过了这部分。从文档中得知:

steps:
- task: myPublisherId.myExtensionId.myContributionId.myTaskName@1 #格式示例
- task: qetza.replacetokens.replacetokens-task.replacetokens@3 #可用示例

在我的情况下,这样可以工作:

# azure-pipelines.yaml

steps:
- task: xerillio.pr-commentator-dev.task.PrCommentator@0
  inputs:
   # ...

摘自清单文件的这些部分:

// vss-extension.json
{
    "id": "pr-commentator-dev",  // == 'myExtensionId'
    "publisher": "xerillio",     // == 'myPublisherId'
    // ...
    "contributions": [
        {
            "id": "task",        // == 'myContributionId'
            "type": "ms.vss-distributed-task.task",
            "targets": ["ms.vss-distributed-task.tasks"],
            "properties": {
                "name": ".task"
            }
        }
    ]
}

// task.json
{
    "name": "PrCommentator",     // == 'myTaskName'
    // ...
}

不幸的是,Azure DevOps Web 设计器/YAML 编辑器在使用这个完全限定名时并不是很有帮助,因为它只显示以下警告:

> 字符串不符合“^PowerShell@2$”的模式。
> 不被接受。有效值:“PowerShell@2”、“PowerShell@1”等 [后面跟着长列表]

但运行管道可以正常工作并运行预期的任务。

英文:

Turns out I missed it in this article in the documentation. From the docs:

steps:
- task: myPublisherId.myExtensionId.myContributionId.myTaskName@1 #format example
- task: qetza.replacetokens.replacetokens-task.replacetokens@3 #working example

In my case, this worked:

# azure-pipelines.yaml

steps:
- task: xerillio.pr-commentator-dev.task.PrCommentator@0
  inputs:
   # ...

Taken from these parts of the manifest files:

// vss-extension.json
{
    "id": "pr-commentator-dev",  // == 'myExtensionId'
    "publisher": "xerillio",     // == 'myPublisherId'
    // ...
    "contributions": [
        {
            "id": "task",        // == 'myContributionId'
            "type": "ms.vss-distributed-task.task",
            "targets": ["ms.vss-distributed-task.tasks"],
            "properties": {
                "name": ".task"
            }
        }
    ]
}

// task.json
{
    "name": "PrCommentator",     // == 'myTaskName'
    // ...
}

Unfortunately, the Azure DevOps web designer/YAML editor isn't very helpful when using this fully qualified name, as it just displays this warning:

> String does not match the pattern of "^PowerShell@2$".
> Value is not accepted. Valid values: "PowerShell@2", "PowerShell@1", ... [long list follows]

But running the pipeline works and runs the expected task.

huangapple
  • 本文由 发表于 2023年5月22日 03:12:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301522.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定