Azure 如何从yaml和jq读取从github复制的文件

Azure 如何从yaml和jq读取从github复制的文件,azure,github,yaml,azure-pipelines,Azure,Github,Yaml,Azure Pipelines,我使用devops管道读取git hub中私有repo中托管的json文件的内容。我可以在管道输出中看到该文件,但jq没有读取该文件,因此出现以下错误:“jq:error:无法打开文件/home/vsts/work/1/s/config.json:没有这样的文件或目录” 这是我的yaml代码: --- resources: repositories: - repository: testrepo type: github endpoint: testendpoint

我使用devops管道读取git hub中私有repo中托管的json文件的内容。我可以在管道输出中看到该文件,但jq没有读取该文件,因此出现以下错误:“jq:error:无法打开文件/home/vsts/work/1/s/config.json:没有这样的文件或目录”

这是我的yaml代码:

   ---
resources:
  repositories:
  - repository: testrepo
    type: github
    endpoint: testendpoint
    name:  test/test01


trigger:
  - none
pool:
  name: Hosted Ubuntu 1604
steps:
  - script: |
      displayName: 'Update the build number in readme.txt' 
      name: JQ
      sudo apt-get install jq
      echo 'installing jq'
  - checkout: testrepo
    path: mytest   # will checkout at $(Pipeline.Workspace)/PutMyCodeHere
  - script: dir ../mytest/

      data=$(jq 'to_entries | map(select(.value.datavalue=="true")) | from_entries' $(Agent.BuildDirectory)/s/data.json )
      echo "$data" 

如何将jq添加到我的json文件?

我可以得到相同的错误消息,我添加了任务复制文件并发布构建工件以检查S文件夹,然后我们可以看到data.json文件

似乎jq问题而不是azure devops管道,您可以将问题提交给jq支持部门

作为一种解决方法,我们可以通过cmd
jq读取json文件。{file name}.json

结果:

更新1

我的测试代码:

resources:
  repositories:
  - repository: vitol
    type: github
    endpoint: GitHubTest
    name:  vitoliutest/vitol

trigger:
  - none
pool:
  name: Hosted Ubuntu 1604
steps:
  - script: |
      displayName: 'Update the build number in readme.txt' 
      name: JQ
      sudo apt-get install jq
      echo 'installing jq'
  - checkout: vitol
    path: mytest   # will checkout at $(Pipeline.Workspace)/PutMyCodeHere

  - task: CopyFiles@2
    inputs:
      SourceFolder: '$(Agent.BuildDirectory)'
      Contents: '**'
      TargetFolder: '$(build.artifactstagingdirectory)'
    
  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(build.artifactstagingdirectory)'
      ArtifactName: 'drop'
      publishLocation: 'Container'

  - script: dir ../mytest/

      jq . $(Agent.BuildDirectory)/*/data.json

您的testrepo似乎没有
data.json
文件。签出步骤的输出是什么?嗨,问题如何?下面的答案解决了你的问题吗?如果没有,你能告诉我关于这个问题的最新信息吗?你好,刘,下面的答案不幸不起作用..你好@rayarelius,我已经编辑了我的答案并添加了测试代码,请你检查一下,然后在这里分享最新消息,如果问题仍然发生,你可以在这里分享最新的错误信息。ThanksHi@rayaurelius,这张票有更新吗?如果您有任何问题,请随时告诉我。