microsoft / azure-pipelines-vscode

VS Code extension for working with Azure Pipelines YAML files
MIT License
163 stars 103 forks source link

Support validation of fully qualified task names (Especially for tasks installed as extensions). #532

Open Clockwork-Muse opened 1 year ago

Clockwork-Muse commented 1 year ago

To allow for better discrimination of the source of tasks, it can be handy to include the fully qualified list of task names, eg:

- task: qetza.replacetokens.replacetokens-task.replacetokens@3
  displayName: Replace Tokens
  inputs:
    rootDirectory: $(TerraformDirectory)
    targetFiles: |
      variables.tf
    tokenPrefix: "#{"
    tokenSuffix: "}"
    actionOnMissing: fail
    escapeType: json
    enableTransforms: true

Unfortunately this currently fails to validate: Fully qualified name fails to validate

Part of this is probably potentially due to the autogenerated (assumedly - I don't control it for my org) yaml schema, which looks like this:

// most properties elided
{
// ...
                        {
                            "description": "Replace tokens in files",
                            "doNotSuggest": false,
                            "ignoreCase": "value",
                            "enum": [
                                "replacetokens@3"
                            ]
                        },
// .....
                    "properties": {
                        "task": {
                            "description": "Replace Tokens\n\nReplace tokens in files",
                            "ignoreCase": "value",
                            "pattern": "^replacetokens@5$"
                        },
                        // ......
                    },
// .....

So it has no concept that there could be a fully qualified name....

50Wliu commented 11 months ago

Yes, I agree this is much needed :). Unfortunately not something this extension can handle - that knowledge comes from ADO itself, and you're correct in assuming that it does all the work necessary to generate that schema file.

michha commented 3 weeks ago

I got this working 😃

The Azure DevOps schema would need to change:

  1. Update Task Property List
    {
    "description": "Replace tokens in text based files",
    "doNotSuggest": false,
    "ignoreCase": "value",
    "enum": [
        "qetza.replacetokens.replacetokens-task.replacetokens@6",
        "replacetokens@6"
    ]
    },
  2. Update pattern matching
    "task": {
    "description": "Replace Tokens\n\nReplace tokens in text based files",
    "ignoreCase": "value",
    "pattern": "^(qetza.replacetokens.replacetokens-task.)?replacetokens@6$"
    },

I downloaded my org schema file, saved it locally, updated it and pointed the VSCode extension to my local file: "azure-pipelines.customSchemaFile": "C:\\your-custom-schema.json"

The whole process (download + edit) could be scripted and ran regulary.

But of course it would be nice if the Azure DevOps team could expand their schema.