【问题标题】:how to read copied file from github from yaml and jq如何从 yaml 和 jq 读取从 github 复制的文件
【发布时间】:2021-01-22 08:23:25
【问题描述】:

我正在使用 devops 管道读取托管在 git hub 中的私有 repo 中的 json 文件的内容。我可以在管道输出中看到文件,但 jq 没有读取文件,它给出了这个错误:“jq:错误:无法打开文件 /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 文件?

【问题讨论】:

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

标签: azure github yaml azure-pipelines


【解决方案1】:

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

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

作为一种解决方法,我们可以通过 cmd jq . {file name}.json 读取 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-09
    • 2012-11-26
    • 2019-01-24
    • 2021-12-27
    • 1970-01-01
    • 2011-04-27
    • 2021-09-24
    • 2019-08-09
    相关资源
    最近更新 更多