Vscode-yaml: String does not match the pattern of "^PowerShell@2$".

Created on 25 Aug 2020  Â·  7Comments  Â·  Source: redhat-developer/vscode-yaml

We have the following task in azure-pipelines.yaml file.

    - task: PublishBuildArtifacts@1
      condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
      displayName: 'Publish Build Artifacts'

The below false positive error will be shown on the PublishBuildArtifacts@1 line.

Publish build artifacts to Azure Pipelines or a Windows file share
String does not match the pattern of "^PowerShell@2$".
Peek Problem (Alt+F8)
No quick fixes available

See related issue.

bug

Most helpful comment

@sheeeng As for Azure Pipelines it is better to use https://marketplace.visualstudio.com/items?itemName=ms-azure-devops.azure-pipelines as it has build in language server specific for azure-pipelines.yaml and that server has support of ignoreCase fields.

All 7 comments

Related schema on schema store: https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json. Looks like something might be getting messed up with the anyOf. Can you paste the erroring yaml so that we can try it out and test

The entire reproducible file are listed below.

---
trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

stages:
- stage: 'BuildStage'
  jobs:
  - job: 'BuildJob'
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: PublishBuildArtifacts@1
      condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
      displayName: 'Publish Build Artifacts'
      inputs:
        pathToPublish: artifacts
        artifactName: artifacts

I also have this issue.

Code:

        steps:
        - task: ArchiveFiles@2
          displayName: package functionapp
          inputs:
            rootFolderOrFile: $(System.DefaultWorkingDirectory)/email-endpoint/functionapp
            includeRootFolder: false
            archiveType: zip
            archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
            replaceExisitingArchive: true

Screenshot of error:
image

@JPinkney @gorkem
I done investigation around this issue, the problem in schema itself, it is used ignoreCase field for some object fields. I cannot find any mentions of ignoreCase in JSON Schema spec, across schema it has different values, like key, all, value.
json-language-server also doesn't have support of this:
Screenshot 2020-10-26 at 11 31 39

Schema used for that JSON is https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json
As you can see it has exactly the same error.

And error happened because object with PublishBuildArtifacts@1 defined as:

        {
          "properties": {
            "task": {
              "description": "Publish build artifacts\n\nPublish build artifacts to Azure Pipelines or a Windows file share",
              "ignoreCase": "value",
              "pattern": "^PublishBuildArtifacts@1$"
            },
            "inputs": {
              "description": "Publish build artifacts inputs",
              "properties": {
                "PathtoPublish": {
                  "type": "string",
                  "description": "Path to publish",
                  "ignoreCase": "key"
                },
                "ArtifactName": {
                  "type": "string",
                  "description": "Artifact name",
                  "ignoreCase": "key"
                },
...
              "additionalProperties": false,
              "required": []
            }
          },
          "firstProperty": [
            "task"
          ],
          "required": [
            "task"
          ]
        }

So next yaml doesn't have error:

---
trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

stages:
- stage: 'BuildStage'
  jobs:
  - job: 'BuildJob'
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: PublishBuildArtifacts@1
      condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
      displayName: 'Publish Build Artifacts'
      inputs:
        PathtoPublish: artifacts
        ArtifactName: artifacts

Need to set pathToPublish -> PathtoPublish and artifactName -> ArtifactName as their names defined in schema.

In the end, I not sure that we need to implement support of ignoreCase, as it is not part of JSON Schema specification.
WDYT?

I think if it's not in the spec we shouldn't support it. Otherwise, we will just end up supporting a bunch of properties that have nothing to do with JSON Schema spec

@sheeeng As for Azure Pipelines it is better to use https://marketplace.visualstudio.com/items?itemName=ms-azure-devops.azure-pipelines as it has build in language server specific for azure-pipelines.yaml and that server has support of ignoreCase fields.

:wave: hey there, I'm the owner of (and person who occasionally has time to support) the VS Code extension for Azure Pipelines. You're correct, we extended JSON Schema to handle some slightly non-standard† YAML stuff we do in Azure Pipelines. In principle, extending JSON Schema is perfectly fine††, but I'm in 💯 agreement that this language server shouldn't go down the path of supporting everyone's non-standard JSON Schema.

If anyone needs a language server specifically for Azure Pipelines, look no further than https://github.com/microsoft/azure-pipelines-language-server. That's the aforementioned fork, which handles the extra JSON Schema.

†Because of underlying systems being non-case-sensitive, we have to be non-case-sensitive in a few places. We also overlay YAML with a mostly-YAML-compatible template language, which means there are edge cases where the file isn't technically YAML at rest.

††For instance this section on formats, though I think we went a slightly different direction.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssbarnea picture ssbarnea  Â·  3Comments

matus-cuper picture matus-cuper  Â·  5Comments

opsarno picture opsarno  Â·  5Comments

Deilan picture Deilan  Â·  6Comments

data-ux picture data-ux  Â·  7Comments